TYPO3 CMS  TYPO3_8-7
ExtDirectNode.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Tree;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 {
27  protected $type = '';
28 
34  protected $leaf = true;
35 
41  protected $expanded = false;
42 
48  protected $expandable = false;
49 
55  protected $draggable = true;
56 
62  protected $isDropTarget = true;
63 
69  protected $text = '';
70 
76  protected $editableText = '';
77 
83  protected $prefix = '';
84 
90  protected $suffix = '';
91 
97  protected $cls = '';
98 
104  protected $qtip = '';
105 
111  protected $spriteIconCode = '';
112 
118  protected $t3TextSourceField = '';
119 
125  protected $t3InCopyMode = false;
126 
132  protected $t3InCutMode = false;
133 
139  protected $record = [];
140 
146  protected $contextInfo = [];
147 
153  protected $labelIsEditable = true;
154 
160  protected $allowChildren = true;
161 
167  public function setType($type)
168  {
169  $this->type = $type;
170  }
171 
177  public function getType()
178  {
179  return $this->type;
180  }
181 
187  public function setLeaf($isLeaf)
188  {
189  $this->leaf = $isLeaf == true;
190  }
191 
197  public function isLeafNode()
198  {
199  return $this->leaf;
200  }
201 
207  public function setExpandable($expandable)
208  {
209  $this->expandable = $expandable == true;
210  }
211 
217  public function isExpandable()
218  {
219  return $this->expandable;
220  }
221 
227  public function setExpanded($expanded)
228  {
229  $this->expanded = $expanded == true;
230  }
231 
237  public function isExpanded()
238  {
239  if ($this->isLeafNode()) {
240  return true;
241  }
242  return $this->expanded;
243  }
244 
250  public function setDraggable($draggable)
251  {
252  $this->draggable = $draggable == true;
253  }
254 
260  public function isDraggable()
261  {
262  return $this->draggable;
263  }
264 
271  {
272  $this->isDropTarget = $isDropTarget == true;
273  }
274 
280  public function isDropTarget()
281  {
282  return $this->isDropTarget;
283  }
284 
293  public function setText($text, $textSourceField = 'title', $prefix = '', $suffix = '')
294  {
295  $this->text = $text;
296  $this->t3TextSourceField = $textSourceField;
297  $this->prefix = $prefix;
298  $this->suffix = $suffix;
299  }
300 
306  public function getText()
307  {
308  return $this->text;
309  }
310 
317  {
318  $this->editableText = $editableText;
319  }
320 
326  public function getEditableText()
327  {
328  return $this->editableText;
329  }
330 
336  public function getTextSourceField()
337  {
339  }
340 
346  public function setInCopyMode($inCopyMode)
347  {
348  $this->t3InCopyMode = $inCopyMode == true;
349  }
350 
356  public function isInCopyMode()
357  {
358  return $this->t3InCopyMode;
359  }
360 
366  public function setInCutMode($inCutMode)
367  {
368  $this->t3InCutMode = $inCutMode == true;
369  }
370 
376  public function isInCutMode()
377  {
378  return $this->t3InCutMode;
379  }
380 
386  public function getPrefix()
387  {
388  return $this->prefix;
389  }
390 
396  public function getSuffix()
397  {
398  return $this->suffix;
399  }
400 
406  public function setCls($class)
407  {
408  $this->cls = $class;
409  }
410 
416  public function getCls()
417  {
418  return $this->cls;
419  }
420 
426  public function setQTip($qtip)
427  {
428  $this->qtip = $qtip;
429  }
430 
436  public function getQTip()
437  {
438  return $this->qtip;
439  }
440 
446  public function setSpriteIconCode($spriteIcon)
447  {
448  $this->spriteIconCode = $spriteIcon;
449  }
450 
456  public function getSpriteIconCode()
457  {
458  return $this->spriteIconCode;
459  }
460 
467  {
468  $this->labelIsEditable = $labelIsEditable == true;
469  }
470 
476  public function isLabelEditable()
477  {
478  return $this->labelIsEditable;
479  }
480 
486  public function setRecord($record)
487  {
488  $this->record = (array)$record;
489  }
490 
496  public function getRecord()
497  {
498  return $this->record;
499  }
500 
506  public function setContextInfo($contextInfo)
507  {
508  $this->contextInfo = (array)$contextInfo;
509  }
510 
516  public function getContextInfo()
517  {
518  return (array)$this->contextInfo;
519  }
520 
526  public function setChildNodes(\TYPO3\CMS\Backend\Tree\TreeNodeCollection $childNodes)
527  {
528  parent::setChildNodes($childNodes);
529  if ($childNodes->count()) {
530  $this->setLeaf(false);
531  }
532  }
533 
540  {
541  $this->allowChildren = $allowChildren == true;
542  }
543 
549  public function canHaveChildren()
550  {
551  return $this->allowChildren;
552  }
553 
560  public function toArray($addChildNodes = true)
561  {
562  $arrayRepresentation = [
563  'serializeClassName' => get_class($this),
564  'id' => $this->getId(),
565  'type' => $this->getType(),
566  'editableText' => $this->getEditableText(),
567  'text' => $this->getPrefix() . $this->getText() . $this->getSuffix(),
568  'cls' => $this->getCls(),
569  'prefix' => $this->getPrefix(),
570  'suffix' => $this->getSuffix(),
571  'qtip' => $this->getQTip(),
572  'expanded' => $this->isExpanded(),
573  'expandable' => $this->isExpandable(),
574  'draggable' => $this->isDraggable(),
575  'isTarget' => $this->isDropTarget(),
576  'spriteIconCode' => $this->getSpriteIconCode(),
577  't3TextSourceField' => $this->getTextSourceField(),
578  't3InCopyMode' => $this->isInCopyMode(),
579  't3InCutMode' => $this->isInCutMode(),
580  't3ContextInfo' => $this->getContextInfo(),
581  'editable' => $this->isLabelEditable(),
582  'allowChildren' => $this->canHaveChildren()
583  ];
584  // only set the leaf attribute if the node has children's,
585  // otherwise you cannot add child's to real leaf nodes
586  if (!$this->isLeafNode()) {
587  $arrayRepresentation['leaf'] = false;
588  }
589  // Some strange environment thingy prevents
590  // the direct copy of an array into an index of the same array
591  $copy = $arrayRepresentation;
592  $arrayRepresentation['nodeData'] = $copy;
593  if ($this->hasChildNodes()) {
594  $arrayRepresentation['children'] = $this->childNodes->toArray();
595  }
596  return $arrayRepresentation;
597  }
598 
604  public function dataFromArray($data)
605  {
606  parent::dataFromArray($data);
607  $this->setType($data['type']);
608  $this->setText($data['label'], $data['t3TextSourceField'], $data['prefix'], $data['suffix']);
609  $this->setEditableText($data['editableText']);
610  $this->setCls($data['cls']);
611  $this->setQTip($data['qtip']);
612  $this->setExpanded($data['expanded']);
613  $this->setExpandable($data['expandable']);
614  $this->setDraggable($data['draggable']);
615  $this->setIsDropTarget($data['isTarget']);
616  $this->setSpriteIconCode($data['spriteIconCode']);
617  $this->setInCopyMode($data['t3InCopyMode']);
618  $this->setInCutMode($data['t3InCutMode']);
619  $this->setContextInfo($data['t3ContextInfo']);
620  $this->setLabelIsEditable($data['editable']);
621  $this->setAllowChildren($data['allowChildren']);
622  // only set the leaf attribute if it's applied
623  // otherwise you cannot insert nodes into this one
624  if (isset($data['leaf'])) {
625  $this->setLeaf(false);
626  }
627  }
628 }
setText($text, $textSourceField='title', $prefix='', $suffix='')
setChildNodes(\TYPO3\CMS\Backend\Tree\TreeNodeCollection $childNodes)