protected function FilterFormatStorageController::postSave

Overrides \Drupal\Core\Config\Entity\ConfigStorageController::postSave().

Overrides ConfigStorageController::postSave

File

drupal/core/modules/filter/lib/Drupal/filter/FilterFormatStorageController.php, line 42
Contains \Drupal\filter\FilterFormatStorageController.

Class

FilterFormatStorageController
Defines the storage controller class for Filter Format entities.

Namespace

Drupal\filter

Code

protected function postSave(EntityInterface $entity, $update) {
  parent::postSave($entity, $update);

  // Clear the static caches of filter_formats() and others.
  filter_formats_reset();
  if ($update) {

    // Clear the filter cache whenever a text format is updated.
    cache('filter')
      ->deleteTags(array(
      'filter_format' => $entity
        ->id(),
    ));
  }
  else {

    // Default configuration of modules and installation profiles is allowed
    // to specify a list of user roles to grant access to for the new format;
    // apply the defined user role permissions when a new format is inserted
    // and has a non-empty $roles property.
    // Note: user_role_change_permissions() triggers a call chain back into
    // filter_permission() and lastly filter_formats(), so its cache must be
    // reset upfront.
    if (($roles = $entity
      ->get('roles')) && ($permission = filter_permission_name($entity))) {
      foreach (user_roles() as $rid => $name) {
        $enabled = in_array($rid, $roles, TRUE);
        user_role_change_permissions($rid, array(
          $permission => $enabled,
        ));
      }
    }
  }
}