calculateDependencies example


    $handler = new EntityField([], 'field', $definition$this->entityTypeManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer, $this->entityRepository, $this->entityFieldManager);

    $title_storage = $this->getBaseFieldStorage();
    $this->entityFieldManager->expects($this->atLeastOnce())
      ->method('getFieldStorageDefinitions')
      ->with('test_entity')
      ->willReturn([
        'title' => $title_storage,
      ]);

    $dependencies = $handler->calculateDependencies();
    $this->assertEmpty($dependencies);
  }

  /** * @covers ::calculateDependencies */
  public function testCalculateDependenciesWithConfiguredField() {
    $definition = [
      'entity_type' => 'test_entity',
      'field_name' => 'body',
    ];
    
// Permissions are always ordered alphabetically to avoid conflicts in the       // exported configuration. If the save is not trusted then the       // configuration will be sorted by StorableConfigBase.       sort($this->permissions);
    }
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();
    // Load all permission definitions.     $permission_definitions = \Drupal::service('user.permissions')->getPermissions();
    $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
return $weight;
    }

    // Sort by label.     return strcmp($a->label()$b->label());
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();
    $this->addDependency('theme', $this->theme);
    return $this;
  }

  /** * {@inheritdoc} */
  public function postSave(EntityStorageInterface $storage$update = TRUE) {
    parent::postSave($storage$update);

    // Entity::postSave() calls Entity::invalidateTagsOnSave(), which only
/** * {@inheritdoc} */
  public function errorElement(array $element, ConstraintViolationInterface $violation, array $form, FormStateInterface $form_state) {
    return $element['value'];
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();

    foreach (['role', 'role2'] as $setting) {
      if (!empty($role_id = $this->getSetting($setting))) {
        // Create a dependency on the role config entity referenced in settings.         $dependencies['config'][] = "user.role.$role_id";
      }
    }

    return $dependencies;
  }

  
$storage = $this->createMock('Drupal\Core\Entity\EntityStorageInterface');
    $storage->expects($this->once())
      ->method('load')
      ->with($format_id)
      ->willReturn($filter_format);

    $this->entityTypeManager->expects($this->once())
      ->method('getStorage')
      ->with('filter_format')
      ->willReturn($storage);

    $dependencies = $entity->calculateDependencies()->getDependencies();
    $this->assertContains('test_module', $dependencies['module']);
    $this->assertContains('filter.format.test', $dependencies['config']);
  }

}
if ($entity->id() == 'deleter') {
        $deletee = $storage->load('deletee');
        $deletee->delete();
      }
    }
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();
    if ($module = \Drupal::state()->get('config_test_new_dependency', FALSE)) {
      $this->addDependency('module', $module);
    }
    return $this;
  }

  /** * {@inheritdoc} */
  public function onDependencyRemoval(array $dependencies) {
    // Record which entities have this method called on and what dependencies
/** * Provides test data for plugin dependencies. */
  public static function providerTestPluginDependencies() {
    $prophet = new Prophet();
    $data = [];

    $plugin = $prophet->prophesize(PluginInspectionInterface::class);

    $dependent_plugin = $prophet->prophesize(PluginInspectionInterface::class)->willImplement(DependentPluginInterface::class);
    $dependent_plugin->calculateDependencies()->willReturn([
      'module' => ['test_module2'],
    ]);

    $data['dependent_plugin_from_module'] = [
      $dependent_plugin,
      ['provider' => 'test_module1'],
      [
        'module' => [
          'test_module1',
          'test_module2',
        ],
      ],
/** * @covers ::calculateDependencies * * @dataProvider providerBasicDependencies */
  public function testCalculateDependencies(array $configuration) {
    $config_dependencies = new ConfigDependencies(['json' => 'serialization']['basic_auth' => 'basic_auth']);

    $rest_config = RestResourceConfig::create($configuration);

    $result = $config_dependencies->calculateDependencies($rest_config);
    $this->assertEquals([
      'module' => ['basic_auth', 'serialization'],
    ]$result);
  }

  /** * @covers ::onDependencyRemoval * @covers ::onDependencyRemovalForMethodGranularity * @covers ::onDependencyRemovalForResourceGranularity * * @dataProvider providerBasicDependencies */
/** * {@inheritdoc} */
  public function getCacheContexts() {
    return ['url'];
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();

    foreach ($this->vocabularyStorage->loadMultiple(array_keys($this->options['vids'])) as $vocabulary) {
      $dependencies[$vocabulary->getConfigDependencyKey()][] = $vocabulary->getConfigDependencyName();
    }
    return $dependencies;
  }

}
/** * {@inheritdoc} */
  public function resetKeyedRoutes() {
    unset($this->keyedRoutes);
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();

    foreach ($this->tipsCollection as $instance) {
      $definition = $instance->getPluginDefinition();
      $this->addDependency('module', $definition['provider']);
    }

    $this->addDependency('module', $this->module);
    return $this;
  }

}

      ];
    }

    return $elements;
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();
    $style_id = $this->getSetting('image_style');
    /** @var \Drupal\image\ImageStyleInterface $style */
    if ($style_id && $style = ImageStyle::load($style_id)) {
      // If this formatter uses a valid image style to display the image, add       // the image style configuration entity as dependency of this formatter.       $dependencies[$style->getConfigDependencyKey()][] = $style->getConfigDependencyName();
    }
    return $dependencies;
  }

  /** * {@inheritdoc} */
'tags' => $cache_tags,
        ],
      ];
    }
    return $elements;
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();
    $style_id = $this->getSetting('responsive_image_style');
    /** @var \Drupal\responsive_image\ResponsiveImageStyleInterface $style */
    if ($style_id && $style = ResponsiveImageStyle::load($style_id)) {
      // Add the responsive image style as dependency.       $dependencies[$style->getConfigDependencyKey()][] = $style->getConfigDependencyName();
    }
    return $dependencies;
  }

}

  public function setTargetType($target_entity_type) {
    $this->targetEntityType = $target_entity_type;
    return $this;
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();
    $target_entity_type = \Drupal::entityTypeManager()->getDefinition($this->targetEntityType);
    $this->addDependency('module', $target_entity_type->getProvider());
    return $this;
  }

  /** * {@inheritdoc} */
  public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);
    \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
  }
if (!empty($bundles) && empty($bundles[$entity->bundle()])) {
      return FALSE;
    }

    return TRUE;
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();

    $entity_type_id = $this->definition['entity_type'];
    $bundle_entity_type = $this->entityTypeManager->getDefinition($entity_type_id)->getBundleEntityType();

    // The bundle entity type might not exist. For example, users do not have     // bundles.     if ($this->entityTypeManager->hasHandler($bundle_entity_type, 'storage')) {
      $bundle_entity_storage = $this->entityTypeManager->getStorage($bundle_entity_type);

      foreach ($bundle_entity_storage->loadMultiple(array_keys($this->options['bundles'])) as $bundle_entity) {
        $dependencies[$bundle_entity->getConfigDependencyKey()][] = $bundle_entity->getConfigDependencyName();
      }
/** * {@inheritdoc} */
  public static function isApplicable(FieldDefinitionInterface $field_definition) {
    return is_a($field_definition->getClass(), ModerationStateFieldItemList::class, TRUE);
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();
    if ($workflow = $this->moderationInformation->getWorkflowForEntityTypeAndBundle($this->fieldDefinition->getTargetEntityTypeId()$this->fieldDefinition->getTargetBundle())) {
      $dependencies[$workflow->getConfigDependencyKey()][] = $workflow->getConfigDependencyName();
    }
    return $dependencies;
  }

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