You are here

function custom_pub_entity_presave in Custom Publishing Options 8

Same name and namespace in other branches
  1. 7 custom_pub.module \custom_pub_entity_presave()

Implements hook_entity_presave().

Parameters

EntityInterface $entity:

File

./custom_pub.module, line 184

Code

function custom_pub_entity_presave(EntityInterface $entity) {
  if ($entity instanceof BaseFieldOverride) {
    $custom_pub_entity = \Drupal::entityTypeManager()
      ->getStorage('custom_publishing_option')
      ->load($entity
      ->getName());
    if ($custom_pub_entity) {
      $dependencies = $entity
        ->get('dependencies');

      // We need to validate if dependency is already added.
      $dependency_name = $custom_pub_entity
        ->getConfigDependencyName();
      if (!in_array($dependency_name, $dependencies['config'])) {
        $dependencies['config'][] = $dependency_name;
        $entity
          ->set('dependencies', $dependencies);
      }
    }
  }
}