NodeTitleItemList.php 863 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<?php

/**
 * @file
 * Contains \Drupal\node\NodeTitleItemList.
 */

namespace Drupal\node;

use Drupal\Core\Field\FieldDefinition;
use Drupal\Core\Field\FieldItemList;

/**
 * @todo This class is a temporary hack for allowing the label of the node title
 *   field to vary by node type. Remove it when https://drupal.org/node/2114707
 *   is solved.
 */
class NodeTitleItemList extends FieldItemList {

  /**
   * {@inheritdoc}
   *
   * The typehint for $definition is a class rather than an interface, because
24
   * there is no interface for setLabel().
25 26 27 28
   */
  public function __construct(FieldDefinition $definition, $name, NodeInterface $node) {
    $node_type = node_type_load($node->getType());
    if (isset($node_type->title_label)) {
29
      $definition->setLabel($node_type->title_label);
30 31 32 33 34
    }
    parent::__construct($definition, $name, $node);
  }

}