You are here

public function Taxonomy::onDependencyRemoval in Workbench Access 8

Informs the plugin that a dependency of the scheme will be deleted.

@todo https://www.drupal.org/node/2579743 make part of a generic interface.

Parameters

array $dependencies: An array of dependencies that will be deleted keyed by dependency type.

Return value

bool TRUE if the workflow settings have been changed, FALSE if not.

Overrides AccessControlHierarchyBase::onDependencyRemoval

See also

\Drupal\Core\Config\ConfigEntityInterface::onDependencyRemoval()

File

src/Plugin/AccessControlHierarchy/Taxonomy.php, line 490

Class

Taxonomy
Defines a hierarchy based on a Vocabulary.

Namespace

Drupal\workbench_access\Plugin\AccessControlHierarchy

Code

public function onDependencyRemoval(array $dependencies) {
  $fields = array_udiff($this->configuration['fields'], array_reduce($dependencies['config'], function (array $carry, $item) {
    if (!$item instanceof FieldConfigInterface) {
      return $carry;
    }
    $carry[] = [
      'field' => $item
        ->getName(),
      'entity_type' => $item
        ->getTargetEntityTypeId(),
      'bundle' => $item
        ->getTargetBundle(),
    ];
    return $carry;
  }, []), function ($array1, $array2) {
    $key1 = sprintf('%s.%s.%s', $array1['field'], $array1['entity_type'], $array1['bundle']);
    $key2 = sprintf('%s.%s.%s', $array2['field'], $array2['entity_type'], $array2['bundle']);
    if ($key1 < $key2) {
      return -1;
    }
    elseif ($key1 > $key2) {
      return 1;
    }
    else {
      return 0;
    }
  });
  $vocabularies = array_diff($this->configuration['vocabularies'], array_reduce($dependencies['config'], function (array $carry, $item) {
    if (!$item instanceof VocabularyInterface) {
      return $carry;
    }
    $carry[] = $item
      ->id();
    return $carry;
  }, []));
  $changed = $fields != $this->configuration['fields'] || $vocabularies != $this->configuration['vocabularies'];
  $this->configuration['fields'] = $fields;
  $this->configuration['vocabularies'] = $vocabularies;
  return $changed;
}