You are here

protected function ContentHubEntityTypeConfig::calculateDependenciesForPreviewImage in Acquia Content Hub 8

Calculates dependencies for Preview Image.

Parameters

\Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager: The Entity Field Manager service.

string $bundle: The entity bundle.

1 call to ContentHubEntityTypeConfig::calculateDependenciesForPreviewImage()
ContentHubEntityTypeConfig::calculateDependencies in src/Entity/ContentHubEntityTypeConfig.php
Calculates dependencies and stores them in the dependency property.

File

src/Entity/ContentHubEntityTypeConfig.php, line 237

Class

ContentHubEntityTypeConfig
Defines a ContentHubEntityTypeConfig configuration entity class.

Namespace

Drupal\acquia_contenthub\Entity

Code

protected function calculateDependenciesForPreviewImage(EntityFieldManagerInterface $entity_field_manager, $bundle) {
  $preview_image_field = $this
    ->getPreviewImageField($bundle);
  $preview_image_style = $this
    ->getPreviewImageStyle($bundle);

  // Calculate dependencies for preview image field.
  if (!empty($preview_image_field)) {

    /** @var \Drupal\Core\Field\FieldDefinitionInterface[] $fields */
    $fields = $entity_field_manager
      ->getFieldDefinitions($this
      ->id(), $bundle);
    $field_config = isset($fields[$preview_image_field]) ? $fields[$preview_image_field]
      ->getConfig($bundle) : FALSE;
    if ($field_config) {
      $this
        ->addDependencies($field_config
        ->getDependencies());
    }

    // Calculate dependencies for preview image style.
    if (!empty($preview_image_style)) {
      $image_style = ImageStyle::load($preview_image_style);
      if (isset($image_style)) {
        $this
          ->addDependency($image_style
          ->getConfigDependencyKey(), $image_style
          ->getConfigDependencyName());
        $this
          ->addDependencies($image_style
          ->getDependencies());
      }
    }
  }
}