function FilterFormat::postSave

Same name in other branches
  1. 8.9.x core/modules/filter/src/Entity/FilterFormat.php \Drupal\filter\Entity\FilterFormat::postSave()
  2. 10 core/modules/filter/src/Entity/FilterFormat.php \Drupal\filter\Entity\FilterFormat::postSave()
  3. 11.x core/modules/filter/src/Entity/FilterFormat.php \Drupal\filter\Entity\FilterFormat::postSave()

Overrides EntityBase::postSave

File

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

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, [
                    $permission => $enabled,
                ]);
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.