Extra Block Types (EBT) - New Layout Builder experience❗

Extra Block Types (EBT) - styled, customizable block types: Slideshows, Tabs, Cards, Accordions and many others. Built-in settings for background, DOM Box, javascript plugins. Experience the future of layout building today.

Demo EBT modules Download EBT modules

❗Extra Paragraph Types (EPT) - New Paragraphs experience

Extra Paragraph Types (EPT) - analogical paragraph based set of modules.

Demo EPT modules Download EPT modules

Scroll

Проверка доступа + кешируемость

30/04/2020, by maria

Проверщики доступа к маршруту, hook_entity_access() и все, что требуется для возврата объекта AccessResultInterface, должны добавить соответствующие метаданные кешируемости.

Если вы еще не читали, прочитайте cache tagscache contexts и max-age.

Параметры проверки доступа

Средство проверки доступа получит различные параметры - по крайней мере, учетную запись пользователя (AccountInterface) и часто объект. Затем он примет решение о свойствах этих параметров.

Кэшируемая зависимость от $parameter должна быть добавлена, если изменение хотя бы одного свойства этого параметра изменит результат доступа.

Например:

$access_result = AccessResult::allowedIf($node->isPublished())
  // Access result depends on a property of the object that might change: it is a cacheable dependency.
  ->addCacheableDependency($node);

Еще один распространенный случай, когда результат доступа зависит от свойства, которое не может быть изменено (обычно идентификатор, UUID). Например, разрешить доступ, если данная учетная запись пользователя является владельцем объекта:

$access_result = AccessResult::allowedIf($node->getOwnerId() === $account->id())
  // Access result depends on the node's owner, the owner might change.
  ->addCacheableDependency($node);

// Access result also depends on a user account, and the ID of the user account can never change. Hence we don't need to add $account as a cacheable dependency.

// But, if $account is the current user, and not some hardcoded user, we also need to make sure we vary this by the current user, so that we don't run this access check once and then reuse its result for all users.
if ($account->id() === \Drupal::currentUser()->id()) {
  $access_result->cachePerUser();
}
Source authors:

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.