addDependencies example


  protected function calculatePluginDependencies(PluginInspectionInterface $instance) {
    $this->addDependencies($this->getPluginDependencies($instance));
  }

  /** * Wraps the module handler. * * @return \Drupal\Core\Extension\ModuleHandlerInterface * The module handler. */
  protected function moduleHandler() {
    return \Drupal::moduleHandler();
  }

  
public function calculateDependencies() {
    parent::calculateDependencies();
    // Add dependencies from the field type plugin. We can not use     // self::calculatePluginDependencies() because instantiation of a field item     // plugin requires a parent entity.     /** @var \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager */
    $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
    $definition = $field_type_manager->getDefinition($this->getType());
    $this->addDependency('module', $definition['provider']);
    // Plugins can declare additional dependencies in their definition.     if (isset($definition['config_dependencies'])) {
      $this->addDependencies($definition['config_dependencies']);
    }
    // Let the field type plugin specify its own dependencies.     // @see \Drupal\Core\Field\FieldItemInterface::calculateDependencies()     $this->addDependencies($definition['class']::calculateDependencies($this));

    // Create dependency on the bundle.     $bundle_config_dependency = $this->entityTypeManager()->getDefinition($this->entity_type)->getBundleConfigDependency($this->bundle);
    $this->addDependency($bundle_config_dependency['type']$bundle_config_dependency['name']);

    return $this;
  }

  
/** * {@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. */
$valid_permissions = array_intersect($this->permissions, array_keys($permission_definitions));
    $invalid_permissions = array_diff($this->permissions, $valid_permissions);
    if (!empty($invalid_permissions)) {
      throw new \RuntimeException('Adding non-existent permissions to a role is not allowed. The incorrect permissions are "' . implode('", "', $invalid_permissions) . '".');
    }
    foreach ($valid_permissions as $permission) {
      // Depend on the module that is providing this permissions.       $this->addDependency('module', $permission_definitions[$permission]['provider']);
      // Depend on any other dependencies defined by permissions granted to       // this role.       if (!empty($permission_definitions[$permission]['dependencies'])) {
        $this->addDependencies($permission_definitions[$permission]['dependencies']);
      }
    }
    return $this;
  }

  /** * {@inheritdoc} */
  public function onDependencyRemoval(array $dependencies) {
    $changed = parent::onDependencyRemoval($dependencies);
    // Load all permission definitions.
Home | Imprint | This part of the site doesn't use cookies.