You are here

public function AccessControlHierarchyBase::disallowedOptions in Workbench Access 8

Gets any options that are set but cannot be changed by the editor.

These options are typically passed as hidden form values so that an editor does not remove sections that they cannot access. See submitEntity() below for the implementation.

Parameters

string $field: The field element from a node form, after running through alterOptions().

Return value

array An array of section ids to remove from a form or list.

Overrides AccessControlHierarchyInterface::disallowedOptions

1 method overrides AccessControlHierarchyBase::disallowedOptions()
Menu::disallowedOptions in src/Plugin/AccessControlHierarchy/Menu.php
Gets any options that are set but cannot be changed by the editor.

File

src/AccessControlHierarchyBase.php, line 220

Class

AccessControlHierarchyBase
Defines a base hierarchy class that others may extend.

Namespace

Drupal\workbench_access

Code

public function disallowedOptions($field) {
  $options = [];
  if (isset($field['widget']['#default_value']) && isset($field['widget']['#options'])) {

    // Default value may be an array or a string.
    if (is_array($field['widget']['#default_value'])) {
      $default_value_array = array_flip($field['widget']['#default_value']);
    }
    else {
      $default_value_array = [
        $field['widget']['#default_value'] => $field['widget']['#default_value'],
      ];
    }
    $options = array_diff_key($default_value_array, $field['widget']['#options']);
  }
  return array_keys($options);
}