text = $text; $this->href = $href; $this->nodes = $nodes; //$this->state = new TreeViewNodeState(); } /** * Return the ID of the entity associated with this node. * Null if this node is not connected with an entity. * * @return int|null */ public function getId(): ?int { return $this->id; } /** * Sets the ID of the entity associated with this node. * Null if this node is not connected with an entity. * * @return $this */ public function setId(?int $id): self { $this->id = $id; return $this; } /** * Returns the node text. * * @return string */ public function getText(): string { return $this->text; } /** * Sets the node text. * * @param string $text The new node text. * * @return TreeViewNode */ public function setText(string $text): self { $this->text = $text; return $this; } /** * Returns the href link. * * @return string|null */ public function getHref(): ?string { return $this->href; } /** * Sets the href link. * * @param string|null $href The new href link. * * @return TreeViewNode */ public function setHref(?string $href): self { $this->href = $href; return $this; } /** * Returns the children nodes of this node. * * @return TreeViewNode[]|null */ public function getNodes(): ?array { return $this->nodes; } /** * Sets the children nodes. * * @param array|null $nodes The new children nodes * * @return TreeViewNode */ public function setNodes(?array $nodes): self { $this->nodes = $nodes; return $this; } public function getState(): ?TreeViewNodeState { return $this->state; } public function setState(TreeViewNodeState $state): self { $this->state = $state; return $this; } public function setDisabled(?bool $disabled): self { //Lazy loading of state, so it does not need to get serialized and transfered, when it is empty. if (null == $this->state) { $this->state = new TreeViewNodeState(); } $this->state->setDisabled($disabled); return $this; } public function setSelected(?bool $selected): self { //Lazy loading of state, so it does not need to get serialized and transfered, when it is empty. if (null == $this->state) { $this->state = new TreeViewNodeState(); } $this->state->setSelected($selected); return $this; } public function getTags(): ?array { return $this->tags; } public function addTag(string $new_tag): self { //Lazy loading tags if (null == $this->tags) { $this->tags = []; } $this->tags[] = $new_tag; return $this; } /** * {@inheritdoc} */ public function jsonSerialize() { $ret = [ 'text' => $this->text, ]; if (null !== $this->href) { $ret['href'] = $this->href; } if (null !== $this->tags) { $ret['tags'] = $this->tags; } if (null !== $this->nodes) { $ret['nodes'] = $this->nodes; } if (null !== $this->state) { $ret['state'] = $this->state; } return $ret; } }