createFromFieldStorageDefinition example


  protected function getFieldDefinition() {
    if (!$this->fieldDefinition) {
      $field_storage_config = $this->getFieldStorageDefinition();
      $this->fieldDefinition = BaseFieldDefinition::createFromFieldStorageDefinition($field_storage_config);
    }
    return $this->fieldDefinition;
  }

  /** * Gets the field storage configuration. * * @return \Drupal\field\FieldStorageConfigInterface * The field storage definition used by this handler */
  protected function getFieldStorageDefinition() {
    

function hook_entity_bundle_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type$bundle, array $base_field_definitions) {
  // Add a property only to nodes of the 'article' bundle.   if ($entity_type->id() == 'node' && $bundle == 'article') {
    $fields = [];
    $storage_definitions = mymodule_entity_field_storage_info($entity_type);
    $fields['mymodule_bundle_field'] = FieldDefinition::createFromFieldStorageDefinition($storage_definitions['mymodule_bundle_field'])
      ->setLabel(t('Bundle Field'));
    return $fields;
  }

}

/** * Alter bundle field definitions. * * @param \Drupal\Core\Field\FieldDefinitionInterface[] $fields * The array of bundle field definitions. * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type definition. * @param string $bundle * The bundle. * * @see hook_entity_base_field_info() * @see hook_entity_base_field_info_alter() * @see hook_entity_bundle_field_info() * * @todo WARNING: This hook will be changed in * https://www.drupal.org/node/2346347. */
/** * Creates a bundle field using a specified factory. * * @param string $factory_name * The factory name to use. * * @return \Drupal\Core\Field\FieldDefinition */
  protected function initializeFieldUsingFactory($factory_name) {
    switch ($factory_name) {
      case 'createFromFieldStorageDefinition':
        return FieldDefinition::createFromFieldStorageDefinition($this->storageDefinition);

      case 'create':
        $definition = FieldDefinition::create($this->fieldType);
        $definition->setFieldStorageDefinition($this->storageDefinition);
        return $definition;

      case 'createFromDataType':
        $definition = FieldDefinition::createFromDataType($this->fieldType);
        $definition->setFieldStorageDefinition($this->storageDefinition);
        return $definition;

      
Home | Imprint | This part of the site doesn't use cookies.