Change record status: 
Introduced in branch: 
8.x-1.x
Introduced in version: 
8.x-1.x-alpha7
Description: 

Workbench access has undergone some major changes between 8.x-1.0 alpha 6 and 8.x-1.0 alpha 7.

If you have developed a custom module around the API as it stood in alpha 6, you may need to update your code to use the newest APIs.

High level changes

The notion of a single active scheme is gone. Instead this has been replaced with a series of scheme config entities.
To interact with these content entites you can load them and use the applies method.

use \Drupal\workbench_access\Entity\AccessSchemeInterface;

$schemes = \Drupal::entityTypeManager()->getStorage('access_scheme')->loadMultiple();
$applicable_schemes = array_filter($schemes, function (AccessSchemeInterface $scheme) use ($my_entity) {
  return $scheme->applies($my_entity->getEntityTypeId(), $my_entity->bundle());
});

Each config entity is tied to an AccessControlHierarchyInterface plugin. To interact with the plugin, use $scheme->getAccessScheme();

use Drupal\workbench_access\Entity\AccessScheme;

$scheme = AccessScheme::load('editorial_section');
$tree = $scheme->getAccessScheme()->getTree();

The taxonomy scheme now supports any entity type with a taxonomy field

So this means you can now apply access controls to media entities and other content-entities.

Upgrade path

If you don't have any custom access controls or modules interacting with Workbench Access, then you should be able to update to alpha7 simply by running the standard update.php or drush updb -y. This will upgrade your configuration to the new scheme-based format.

As with any update.php that changes configuration, you should export and commit your configuration.

Views

If you have built views using fields and filters provided by alpha6 or earlier, you will notice that your fields/filters are now named 'Legacy'. It is recommended that you edit these views and replace them with the new fields/filters provided by the appropriate scheme. When you are done, you can disable these legacy fields by deleting the workbench_access_upgraded_scheme_id state key. e.g. drush sdel workbench_access_upgraded_scheme_id.

API changes

As part of this change, there were some major API changes

Drupal\workbench_access\WorkbenchAccessManagerInterface

The public API for the manager is greatly simplified. While we were making this change, we also removed deprecated code that was earlier moved from the manager to distinct role and user section storage services. The before and after methods are shown below

Before After
getSchemes() Removed, just use the built in getDefinitions(), found on any plugin manager
getScheme($id) Removed, just use the built in getInstance($id), found on any plugin manager
getActiveScheme() Removed, work with the access scheme config entities instead, calling getAccsesScheme() on each
getActiveTree Removed, work with the access scheme config entities instead, calling getAccessScheme()->getTree() on each
getElement($id) Removed, work with the access scheme config entities instead, calling getAccessScheme()->load($id) on each
getDefaultValue() Removed, no longer needed
addEntity Removed, was empty code already
removeEntity Removed, was empty code already
checkTree(array $entity_sections, array $user_sections) Signature changed to a static method, and arguments changes. checkTree(AccessSchemeInterface $scheme, array $entity_sections, array $user_sections)
getAllSections($root_only = FALSE) Signature changed to a static method and arguments changegetAllSections(AccessSchemeInterface $scheme, $root_only = FALSE)
userInAll($uid) Signature changes, userInAll(AccessSchemeInterface $scheme, $uid)
flushFields Removed, flushing happens automatically when an access scheme config entity is deleted
resetTree Removed, work with the access scheme config entities instead, calling getAccessScheme()->resetTree() on each

Drupal\workbench_access\AccessControlHierarchyInterface

Before After
status() Removed, not needed now that there are multiple active schemes tied to config entities
options() Removed, was only used internally to build options in the configuration form, should never have been a public method
getFields($entity_type, $bundle, $parents) Removed, was only used internally to build options in the configuration form, should never have been a public method
getEntityValues($entity, $field) getEntityValues($entity). Plugins are responsible for their own fields, so no need to pass in the field name.
configForm($form, $form_state) Renamed to buildConfigurationForm to bring into line with ConfigurablePluginInterface in core. Note that the $form_state passed is an instance of SubFormState, which means that the settings form values are in the top-level of the form state values, instead of nested inside a settings key.
configValudate($form, $form_state) Renamed to validateConfigurationForm($form, $form_state) to bring in line with ConfigurablePluginInterface in core. Note that the $form_state passed is an instance of SubFormState so the values are in the top level, rather than nested in a settings key
configSubmit Renamed to submitConfigurationForm($form, $form_state) to bring in line with ConfigurablePluginInterface in core. Note that the $form_state passed is an instance of SubFormState so the values are in the top level, rather than nested in a settings key
checkEntityAccess($entity, $op, $account, $manager) Signature changed to checkEntityAccess(AccessSchemeInterface $scheme, $entity, $op, $account, $manager)
alterOptions($field, $manager, $user_sections) Renamed to alterForm and signature changed to alterForm(AccessSchemeInterface $scheme, array &$form, ContentEntityInterface $entity) . Now modifies the form by reference
getViewsJoin($table, $key, $alias) Signature changed to getViewsJoin($entity_type, $key, $alias)
New method applies($entity_type_id, $bundle) tells the module if this scheme applies to a given entity type and bundle
New method viewsData(array &$data, AccessSchemeInterface $scheme) - gives plugins the chance to alter views data
New method massageFormValues(ContentEntityInterface $entity, FormStateInterface $form_state, array $hidden_values) - gives plugins the chance to modify the content entity being edited in order to e.g. add back values that were hidden from the user for access sake but should be retained in the entity.
New method onDependecyRemoval(array $dependencies) - gives plugins a chance to react to deletion of dependencies. E.g. if the menu scheme is configured to use a given node type, and that node type is deleted, then the plugin has a chance to remove that node type from its configuration, triggering an update in the config entity, ensuring configuration can be deployed

Drupal\workbench_access\RoleSectionStorageInterface

The following methods were modified to include the AccessSchemeInterface $scheme argument

  • addRole(AccessSchemeInterface $scheme, $role_id, array $sections)
  • removeRole(AccessSchemeInterface $scheme, $role_id, array $sections)
  • getRoles(AccessSchemeInterface $scheme, $id)
  • flushRoles(AccessSchemeInterface $scheme)
  • getRoleSections(AccessSchemeInterface $scheme, AccountInterface $account)

Drupal\workbench_access\UserSectionStorageInterface

The following methods were modified to include the AccessSchemeInterface $scheme argument

  • addUser(AccessSchemeInterface $scheme, $user_id, array $sections)
  • removeUser(AccessSchemeInterface $scheme, $user_id, array $sections)
  • getEditors(AccessSchemeInterface $scheme, $id)
  • getUserSections(AccessSchemeInterface $scheme, $uid, $add_roles = FALSE)
  • flushUsers(AccessSchemeInterface $scheme)
Impacts: 
Site builders, administrators, editors
Module developers