FilterFormat::postSave

public FilterFormat::postSave(EntityStorageInterface $storage, $update = TRUE)

Acts on a saved entity before the insert or update hook is invoked.

Used after the entity is saved, but before invoking the insert or update hook. Note that in case of translatable content entities this callback is only fired on their current translation. It is up to the developer to iterate over all translations if needed.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.

bool $update: TRUE if the entity has been updated, or FALSE if it has been inserted.

Overrides Entity::postSave

File

core/modules/filter/src/Entity/FilterFormat.php, line 208

Class

FilterFormat
Represents a text format.

Namespace

Drupal\filter\Entity

Code

public function postSave(EntityStorageInterface $storage, $update = TRUE) {
  parent::postSave($storage, $update);

  // Clear the static caches of filter_formats() and others.
  filter_formats_reset();

  if (!$update && !$this->isSyncing()) {
    // 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
    // \Drupal\filter\FilterPermissions::permissions() and lastly
    // filter_formats(), so its cache must be reset upfront.
    if (($roles = $this->get('roles')) && $permission = $this->getPermissionName()) {
      foreach (user_roles() as $rid => $name) {
        $enabled = in_array($rid, $roles, TRUE);
        user_role_change_permissions($rid, array($permission => $enabled));
      }
    }
  }
}
doc_Drupal
2016-10-29 09:14:33
Comments
Leave a Comment

Please login to continue.