isReusable example

/** * {@inheritdoc} */
  public function validate($entity, Constraint $constraint) {
    // This prevents saving an update to the block via a host entity's form if     // the host entity has had other changes made via the API instead of the     // entity form, such as a revision revert. This is safe, for example, in the     // Layout Builder the inline blocks are not saved until the whole layout is     // saved, in which case Layout Builder forces a new revision for the block.     // @see \Drupal\layout_builder\InlineBlockEntityOperations::handlePreSave.     if ($entity instanceof BlockContentInterface && !$entity->isReusable()) {
      return;
    }
    parent::validate($entity$constraint);
  }

}
$container->get('event_dispatcher')
    );
  }

  /** * {@inheritdoc} */
  protected function checkAccess(EntityInterface $entity$operation, AccountInterface $account) {
    assert($entity instanceof BlockContentInterface);
    $bundle = $entity->bundle();
    $forbidIfNotDefaultAndLatest = fn (): AccessResultInterface => AccessResult::forbiddenIf($entity->isDefaultRevision() && $entity->isLatestRevision());
    $forbidIfNotReusable = fn (): AccessResultInterface => AccessResult::forbiddenIf($entity->isReusable() === FALSE, sprintf('Block content must be reusable to use `%s` operation', $operation));
    $access = match ($operation) {
      // Allow view and update access to user with the 'edit any (type) block       // content' permission or the 'administer blocks' permission.       'view' => AccessResult::allowedIf($entity->isPublished())
        ->orIf(AccessResult::allowedIfHasPermissions($account[
          'access block library',
        ]))->orIf(AccessResult::allowedIfHasPermissions($account[
          'administer block content',
        ])),
      'update' => AccessResult::allowedIfHasPermissions($account[
        'access block library',
        

  public function getTheme() {
    return $this->theme;
  }

  /** * {@inheritdoc} */
  public function postSave(EntityStorageInterface $storage$update = TRUE) {
    parent::postSave($storage$update);
    if ($this->isReusable() || (isset($this->original) && $this->original->isReusable())) {
      static::invalidateBlockPluginCache();
    }
  }

  /** * {@inheritdoc} */
  public static function preDelete(EntityStorageInterface $storage, array $entities) {
    parent::preDelete($storage$entities);

    /** @var \Drupal\block_content\BlockContentInterface $block */
    
$form['revision']['#disabled'] = TRUE;
    $form['revision']['#description'] = $this->t('Revisions must be required when moderation is enabled.');
  }

  /** * {@inheritdoc} */
  public function isModeratedEntity(ContentEntityInterface $entity) {
    // Only reusable blocks can be moderated individually. Non-reusable or     // inline blocks are moderated as part of the entity they are a composite     // of.     return $entity->isReusable();
  }

}
Home | Imprint | This part of the site doesn't use cookies.