TYPO3  7.6
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 = array();
140 
146  protected $contextInfo = array();
147 
153  protected $labelIsEditable = true;
154 
160  protected $allowChildren = true;
161 
168  public function setType($type)
169  {
170  $this->type = $type;
171  }
172 
178  public function getType()
179  {
180  return $this->type;
181  }
182 
189  public function setLeaf($isLeaf)
190  {
191  $this->leaf = $isLeaf == true;
192  }
193 
199  public function isLeafNode()
200  {
201  return $this->leaf;
202  }
203 
210  public function setExpandable($expandable)
211  {
212  $this->expandable = $expandable == true;
213  }
214 
220  public function isExpandable()
221  {
222  return $this->expandable;
223  }
224 
231  public function setExpanded($expanded)
232  {
233  $this->expanded = $expanded == true;
234  }
235 
241  public function isExpanded()
242  {
243  if ($this->isLeafNode()) {
244  return true;
245  }
246  return $this->expanded;
247  }
248 
255  public function setDraggable($draggable)
256  {
257  $this->draggable = $draggable == true;
258  }
259 
265  public function isDraggable()
266  {
267  return $this->draggable;
268  }
269 
277  {
278  $this->isDropTarget = $isDropTarget == true;
279  }
280 
286  public function isDropTarget()
287  {
288  return $this->isDropTarget;
289  }
290 
300  public function setText($text, $textSourceField = 'title', $prefix = '', $suffix = '')
301  {
302  $this->text = $text;
303  $this->t3TextSourceField = $textSourceField;
304  $this->prefix = $prefix;
305  $this->suffix = $suffix;
306  }
307 
313  public function getText()
314  {
315  return $this->text;
316  }
317 
325  {
326  $this->editableText = $editableText;
327  }
328 
334  public function getEditableText()
335  {
336  return $this->editableText;
337  }
338 
344  public function getTextSourceField()
345  {
347  }
348 
355  public function setInCopyMode($inCopyMode)
356  {
357  $this->t3InCopyMode = $inCopyMode == true;
358  }
359 
365  public function isInCopyMode()
366  {
367  return $this->t3InCopyMode;
368  }
369 
376  public function setInCutMode($inCutMode)
377  {
378  $this->t3InCutMode = $inCutMode == true;
379  }
380 
386  public function isInCutMode()
387  {
388  return $this->t3InCutMode;
389  }
390 
396  public function getPrefix()
397  {
398  return $this->prefix;
399  }
400 
406  public function getSuffix()
407  {
408  return $this->suffix;
409  }
410 
417  public function setCls($class)
418  {
419  $this->cls = $class;
420  }
421 
427  public function getCls()
428  {
429  return $this->cls;
430  }
431 
438  public function setQTip($qtip)
439  {
440  $this->qtip = $qtip;
441  }
442 
448  public function getQTip()
449  {
450  return $this->qtip;
451  }
452 
459  public function setSpriteIconCode($spriteIcon)
460  {
461  $this->spriteIconCode = $spriteIcon;
462  }
463 
469  public function getSpriteIconCode()
470  {
471  return $this->spriteIconCode;
472  }
473 
481  {
482  $this->labelIsEditable = $labelIsEditable == true;
483  }
484 
490  public function isLabelEditable()
491  {
492  return $this->labelIsEditable;
493  }
494 
501  public function setRecord($record)
502  {
503  $this->record = (array)$record;
504  }
505 
511  public function getRecord()
512  {
513  return $this->record;
514  }
515 
522  public function setContextInfo($contextInfo)
523  {
524  $this->contextInfo = (array)$contextInfo;
525  }
526 
532  public function getContextInfo()
533  {
534  return (array)$this->contextInfo;
535  }
536 
543  public function setChildNodes(\TYPO3\CMS\Backend\Tree\TreeNodeCollection $childNodes)
544  {
545  parent::setChildNodes($childNodes);
546  if ($childNodes->count()) {
547  $this->setLeaf(false);
548  }
549  }
550 
558  {
559  $this->allowChildren = $allowChildren == true;
560  }
561 
567  public function canHaveChildren()
568  {
569  return $this->allowChildren;
570  }
571 
578  public function toArray($addChildNodes = true)
579  {
580  $arrayRepresentation = array(
581  'serializeClassName' => get_class($this),
582  'id' => $this->getId(),
583  'type' => $this->getType(),
584  'editableText' => $this->getEditableText(),
585  'text' => $this->getPrefix() . $this->getText() . $this->getSuffix(),
586  'cls' => $this->getCls(),
587  'prefix' => $this->getPrefix(),
588  'suffix' => $this->getSuffix(),
589  'qtip' => $this->getQTip(),
590  'expanded' => $this->isExpanded(),
591  'expandable' => $this->isExpandable(),
592  'draggable' => $this->isDraggable(),
593  'isTarget' => $this->isDropTarget(),
594  'spriteIconCode' => $this->getSpriteIconCode(),
595  't3TextSourceField' => $this->getTextSourceField(),
596  't3InCopyMode' => $this->isInCopyMode(),
597  't3InCutMode' => $this->isInCutMode(),
598  't3ContextInfo' => $this->getContextInfo(),
599  'editable' => $this->isLabelEditable(),
600  'allowChildren' => $this->canHaveChildren()
601  );
602  // only set the leaf attribute if the node has children's,
603  // otherwise you cannot add child's to real leaf nodes
604  if (!$this->isLeafNode()) {
605  $arrayRepresentation['leaf'] = false;
606  }
607  // Suhosin(?) or some other strange environment thingy prevents
608  // the direct copy of an array into an index of the same array
609  $copy = $arrayRepresentation;
610  $arrayRepresentation['nodeData'] = $copy;
611  if ($this->hasChildNodes()) {
612  $arrayRepresentation['children'] = $this->childNodes->toArray();
613  }
614  return $arrayRepresentation;
615  }
616 
623  public function dataFromArray($data)
624  {
625  parent::dataFromArray($data);
626  $this->setType($data['type']);
627  $this->setText($data['label'], $data['t3TextSourceField'], $data['prefix'], $data['suffix']);
628  $this->setEditableText($data['editableText']);
629  $this->setCls($data['cls']);
630  $this->setQTip($data['qtip']);
631  $this->setExpanded($data['expanded']);
632  $this->setExpandable($data['expandable']);
633  $this->setDraggable($data['draggable']);
634  $this->setIsDropTarget($data['isTarget']);
635  $this->setSpriteIconCode($data['spriteIconCode']);
636  $this->setInCopyMode($data['t3InCopyMode']);
637  $this->setInCutMode($data['t3InCutMode']);
638  $this->setContextInfo($data['t3ContextInfo']);
639  $this->setLabelIsEditable($data['editable']);
640  $this->setAllowChildren($data['allowChildren']);
641  // only set the leaf attribute if it's applied
642  // otherwise you cannot insert nodes into this one
643  if (isset($data['leaf'])) {
644  $this->setLeaf(false);
645  }
646  }
647 }