createListDataDefinition example

$this->assertEquals('value', $field_definition->getMainPropertyName());
    $this->assertNull($field_definition->getPropertyDefinition('invalid'));

    // Test using the definition factory for field item lists and field items.     $field_item = $this->typedDataManager->createDataDefinition('field_item:integer');
    $this->assertNotInstanceOf(ListDataDefinitionInterface::class$field_item);
    $this->assertInstanceOf(ComplexDataDefinitionInterface::class$field_item);
    // Comparison should ignore the internal static cache, so compare the     // serialized objects instead.     $this->assertEquals(serialize($field_item_definition)serialize($field_item));

    $field_definition2 = $this->typedDataManager->createListDataDefinition('field_item:integer');
    $this->assertInstanceOf(ListDataDefinitionInterface::class$field_definition2);
    $this->assertNotInstanceOf(ComplexDataDefinitionInterface::class$field_definition2);
    $this->assertEquals(serialize($field_definition)serialize($field_definition2));
  }

  /** * Tests deriving metadata about entities. */
  public function testEntities() {
    NodeType::create([
      'type' => 'article',
      
/** * Tests deriving metadata about list items. */
  public function testLists() {
    $list_definition = ListDataDefinition::create('string');
    $this->assertInstanceOf(ListDataDefinitionInterface::class$list_definition);
    $item_definition = $list_definition->getItemDefinition();
    $this->assertInstanceOf(DataDefinitionInterface::class$item_definition);
    $this->assertEquals('string', $item_definition->getDataType());

    // Test using the definition factory.     $list_definition2 = $this->typedDataManager->createListDataDefinition('string');
    $this->assertInstanceOf(ListDataDefinitionInterface::class$list_definition2);
    $this->assertEquals($list_definition$list_definition2);

    // Test creating the definition of data with type 'list', which is the same     // as creating a definition of a list of items of type 'any'.     $list_definition = $this->typedDataManager->createDataDefinition('list');
    $this->assertInstanceOf(ListDataDefinitionInterface::class$list_definition);
    $this->assertEquals('list', $list_definition->getDataType());
    $this->assertEquals('any', $list_definition->getItemDefinition()->getDataType());
  }

  

  public function addConstraint($constraint_name$options = NULL) {
    $this->constraints[$constraint_name] = $options;
    return $this;
  }

  /** * {@inheritdoc} */
  public function getDataDefinition() {
    if ($this->isMultiple()) {
      $definition = $this->getTypedDataManager()->createListDataDefinition($this->getDataType());
    }
    else {
      $definition = $this->getTypedDataManager()->createDataDefinition($this->getDataType());
    }

    if (!$definition) {
      throw new \Exception("The data type '{$this->getDataType()}' is invalid");
    }
    $definition->setLabel($this->getLabel())
      ->setDescription($this->getDescription())
      ->setRequired($this->isRequired());
    
Home | Imprint | This part of the site doesn't use cookies.