You are here

public function FilterFormat::postSave in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/filter/src/Entity/FilterFormat.php \Drupal\filter\Entity\FilterFormat::postSave()
  2. 9 core/modules/filter/src/Entity/FilterFormat.php \Drupal\filter\Entity\FilterFormat::postSave()

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 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,
        ]);
      }
    }
  }
}