calculateStorageDependencies example


      }
    }

    return $dependencies;
  }

  /** * {@inheritdoc} */
  public static function calculateStorageDependencies(FieldStorageDefinitionInterface $field_definition) {
    $dependencies = parent::calculateStorageDependencies($field_definition);
    $target_entity_type = \Drupal::entityTypeManager()->getDefinition($field_definition->getSetting('target_type'));
    $dependencies['module'][] = $target_entity_type->getProvider();
    return $dependencies;
  }

  /** * {@inheritdoc} */
  public static function onDependencyRemoval(FieldDefinitionInterface $field_definition, array $dependencies) {
    $changed = parent::onDependencyRemoval($field_definition$dependencies);
    $entity_type_manager = \Drupal::entityTypeManager();
    
/** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();
    // Ensure the field is dependent on the providing module.     $this->addDependency('module', $this->getTypeProvider());
    // Ask the field type for any additional storage dependencies.     // @see \Drupal\Core\Field\FieldItemInterface::calculateStorageDependencies()     $definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($this->getType(), FALSE);
    $this->addDependencies($definition['class']::calculateStorageDependencies($this));

    // Ensure the field is dependent on the provider of the entity type.     $entity_type = \Drupal::entityTypeManager()->getDefinition($this->entity_type);
    $this->addDependency('module', $entity_type->getProvider());
    return $this;
  }

  /** * Prepares saving an updated field definition. * * @param \Drupal\Core\Entity\EntityStorageInterface $storage * The entity storage. */
Home | Imprint | This part of the site doesn't use cookies.