getConfigDependencyKey example

$target_entity_type = $entity_type_manager->getDefinition($field_definition->getFieldStorageDefinition()->getSetting('target_type'));

    // Depend on default values entity types configurations.     if ($default_value = $field_definition->getDefaultValueLiteral()) {
      $entity_repository = \Drupal::service('entity.repository');
      foreach ($default_value as $value) {
        if (is_array($value) && isset($value['target_uuid'])) {
          $entity = $entity_repository->loadEntityByUuid($target_entity_type->id()$value['target_uuid']);
          // If the entity does not exist do not create the dependency.           // @see \Drupal\Core\Field\EntityReferenceFieldItemList::processDefaultValue()           if ($entity) {
            $dependencies[$target_entity_type->getConfigDependencyKey()][] = $entity->getConfigDependencyName();
          }
        }
      }
    }

    // Depend on target bundle configurations. Dependencies for 'target_bundles'     // also covers the 'auto_create_bundle' setting, if any, because its value     // is included in the 'target_bundles' list.     $handler = $field_definition->getSetting('handler_settings');
    if (!empty($handler['target_bundles'])) {
      if ($bundle_entity_type_id = $target_entity_type->getBundleEntityType()) {
        
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
      $bundle = $entity_display->getTargetBundle();
      $args = [
        '%entity_type' => $entity_type->getCollectionLabel(),
        '@entity_type_singular' => $entity_type->getSingularLabel(),
        '@entity_type_plural' => $entity_type->getPluralLabel(),
        '%bundle' => $this->bundleInfo->getBundleInfo($entity_type_id)[$bundle]['label'],
      ];
      // These permissions are generated on behalf of $entity_display entity       // display, therefore add this entity display as a config dependency.       $dependencies = [
        $entity_display->getConfigDependencyKey() => [
          $entity_display->getConfigDependencyName(),
        ],
      ];
      if ($entity_type->hasKey('bundle')) {
        $permissions["configure all $bundle $entity_type_id layout overrides"] = [
          'title' => $this->t('%entity_type - %bundle: Configure all layout overrides', $args),
          'warning' => $this->t('Warning: Allows configuring the layout even if the user cannot edit the @entity_type_singular itself.', $args),
          'dependencies' => $dependencies,
        ];
        $permissions["configure editable $bundle $entity_type_id layout overrides"] = [
          'title' => $this->t('%entity_type - %bundle: Configure layout overrides for @entity_type_plural that the user can edit', $args),
          
if ($permission = $format->getPermissionName()) {
        $permissions[$permission] = [
          'title' => $this->t('Use the <a href=":url">@label</a> text format', [':url' => $format->toUrl()->toString(), '@label' => $format->label()]),
          'description' => [
            '#prefix' => '<em>',
            '#markup' => $this->t('Warning: This permission may have security implications depending on how the text format is configured.'),
            '#suffix' => '</em>',
          ],
          // This permission is generated on behalf of $format text format,           // therefore add this text format as a config dependency.           'dependencies' => [
            $format->getConfigDependencyKey() => [
              $format->getConfigDependencyName(),
            ],
          ],
        ];
      }
    }
    return $permissions;
  }

}
'%transition' => $transition->label(),
          ]),
          'description' => $this->formatPlural(
            count($transition->from()),
            'Move content from %from state to %to state.',
            'Move content from %from states to %to state.', [
              '%from' => implode(', ', array_map([State::class, 'labelCallback']$transition->from())),
              '%to' => $transition->to()->label(),
            ]
          ),
          'dependencies' => [
            $workflow->getConfigDependencyKey() => [$workflow->getConfigDependencyName()],
          ],
        ];
      }
    }

    return $permissions;
  }

}
// The value might be a string due to the wrong plugin being used for role     // field data, and subsequently the incorrect config schema object and     // value. In the empty case stop early. Otherwise we cast it to an array     // later.     if (is_string($this->value) && $this->value === '') {
      return [];
    }

    foreach ((array) $this->value as $role_id) {
      if ($role = $this->roleStorage->load($role_id)) {
        $dependencies[$role->getConfigDependencyKey()][] = $role->getConfigDependencyName();
      }
      else {
        trigger_error("The {$role_id} role does not exist. You should review and fix the configuration of the {$this->view->id()} view.", E_USER_WARNING);
      }
    }
    return $dependencies;
  }

}
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;
  }

}

  public function __sleep() {
    $this->typedData = NULL;
    return $this->traitSleep();
  }

  /** * {@inheritdoc} */
  public function getConfigDependencyKey() {
    return $this->getEntityType()->getConfigDependencyKey();
  }

  /** * {@inheritdoc} */
  public function getConfigDependencyName() {
    return $this->getEntityTypeId() . ':' . $this->bundle() . ':' . $this->uuid();
  }

  /** * {@inheritdoc} */
private function buildBundlePermission(EntityTypeInterface $entity_type, string $bundle, array $bundle_info) {
    $permission = [
      'title' => $this->t('Translate %bundle_label @entity_label', [
        '@entity_label' => $entity_type->getSingularLabel(),
        '%bundle_label' => $bundle_info['label'] ?? $bundle,
      ]),
    ];

    // If the entity type uses bundle entities, add a dependency on the bundle.     $bundle_entity_type = $entity_type->getBundleEntityType();
    if ($bundle_entity_type && $bundle_entity = $this->entityTypeManager->getStorage($bundle_entity_type)->load($bundle)) {
      $permission['dependencies'][$bundle_entity->getConfigDependencyKey()][] = $bundle_entity->getConfigDependencyName();
    }
    else {
      $permission['dependencies']['module'][] = $entity_type->getProvider();
    }
    return $permission;
  }

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

    $view_mode = $this->entityTypeManager
      ->getStorage('entity_view_mode')
      ->load($this->getEntityTypeId() . '.' . $this->options['view_mode']);
    if ($view_mode) {
      $dependencies[$view_mode->getConfigDependencyKey()][] = $view_mode->getConfigDependencyName();
    }

    return $dependencies;
  }

}


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

    if ($workflow_ids = $this->getWorkflowIds()) {
      /** @var \Drupal\workflows\WorkflowInterface $workflow */
      foreach ($this->workflowStorage->loadMultiple($workflow_ids) as $workflow) {
        $dependencies[$workflow->getConfigDependencyKey()][] = $workflow->getConfigDependencyName();
      }
    }

    return $dependencies;
  }

  /** * {@inheritdoc} */
  public function onDependencyRemoval(array $dependencies) {
    // See if this handler is responsible for any of the dependencies being

  public function calculateDependencies() {
    $dependencies = [];
    // Combine the view modes from both config parameters.     $view_modes = $this->settings['allowed_view_modes'] + [$this->settings['default_view_mode']];
    $view_modes = array_unique(array_values($view_modes));
    $dependencies += ['config' => []];
    $storage = $this->entityTypeManager->getStorage('entity_view_mode');
    foreach ($view_modes as $view_mode) {
      if ($entity_view_mode = $storage->load('media.' . $view_mode)) {
        $dependencies[$entity_view_mode->getConfigDependencyKey()][] = $entity_view_mode->getConfigDependencyName();
      }
    }
    return $dependencies;
  }

}
$form_state->setValue(['access_options', 'role']$role);
  }

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

    foreach (array_keys($this->options['role']) as $rid) {
      if ($role = $this->roleStorage->load($rid)) {
        $dependencies[$role->getConfigDependencyKey()][] = $role->getConfigDependencyName();
      }
    }

    return $dependencies;
  }

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

    $bundle_entity_type = $this->entityType->getBundleEntityType();
    $bundle_entity_storage = $this->entityTypeManager->getStorage($bundle_entity_type);

    foreach (array_keys($this->value) as $bundle) {
      if ($bundle_entity = $bundle_entity_storage->load($bundle)) {
        $dependencies[$bundle_entity->getConfigDependencyKey()][] = $bundle_entity->getConfigDependencyName();
      }
    }

    return $dependencies;
  }

}
$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();
      }
    }

    return $dependencies;
  }

  /** * {@inheritdoc} */
  public function getContextDefinition() {
    return EntityContextDefinition::fromEntityTypeId($this->definition['entity_type'])
      
/** * {@inheritdoc} */
  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();

    // Ensure that we don't add dependencies for placeholders.     // @todo Use a method to check for tokens in     // https://www.drupal.org/node/2396607.     if (!str_contains($this->options['target'], '{{')) {
      if ($entity = $this->entityRepository->loadEntityByConfigTarget($this->entityType, $this->options['target'])) {
        $dependencies[$this->entityTypeManager->getDefinition($this->entityType)->getConfigDependencyKey()][] = $entity->getConfigDependencyName();
      }
    }

    return $dependencies;
  }

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