/**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $filter_format, $operation, $langcode, AccountInterface $account)
 {
     /** @var \Drupal\filter\FilterFormatInterface $filter_format */
     // All users are allowed to use the fallback filter.
     if ($operation == 'use') {
         if ($filter_format->isFallbackFormat()) {
             return AccessResult::allowed();
         } else {
             return AccessResult::allowedIfHasPermission($account, $filter_format->getPermissionName());
         }
     }
     // The fallback format may not be disabled.
     if ($operation == 'disable' && $filter_format->isFallbackFormat()) {
         return AccessResult::forbidden();
     }
     // We do not allow filter formats to be deleted through the UI, because that
     // would render any content that uses them unusable.
     if ($operation == 'delete') {
         return AccessResult::forbidden();
     }
     if (in_array($operation, array('disable', 'update'))) {
         return parent::checkAccess($filter_format, $operation, $langcode, $account);
     }
     // No opinion.
     return AccessResult::neutral();
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     // Check whether this is the fallback text format. This format is available
     // to all roles and cannot be disabled via the admin interface.
     $row['label'] = $entity->label();
     $row['roles'] = [];
     if ($entity->isFallbackFormat()) {
         $fallback_choice = $this->configFactory->get('filter.settings')->get('always_show_fallback_choice');
         if ($fallback_choice) {
             $row['roles']['#markup'] = $this->t('All roles may use this format');
         } else {
             $row['roles']['#markup'] = $this->t('This format is shown when no other formats are available');
         }
         // Emphasize the fallback role text since it is important to understand
         // how it works which configuring filter formats. Additionally, it is not
         // a list of roles unlike the other values in this column.
         $row['roles']['#prefix'] = '<em>';
         $row['roles']['#suffix'] = '</em>';
     } else {
         $row['roles'] = ['#theme' => 'item_list', '#items' => filter_get_roles_by_format($entity), '#empty' => $this->t('No roles may use this format'), '#context' => ['list_style' => 'comma-list']];
     }
     return $row + parent::buildRow($entity);
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     // Check whether this is the fallback text format. This format is available
     // to all roles and cannot be disabled via the admin interface.
     if ($entity->isFallbackFormat()) {
         $row['label'] = SafeMarkup::placeholder($entity->label());
         $fallback_choice = $this->configFactory->get('filter.settings')->get('always_show_fallback_choice');
         if ($fallback_choice) {
             $roles_markup = SafeMarkup::placeholder($this->t('All roles may use this format'));
         } else {
             $roles_markup = SafeMarkup::placeholder($this->t('This format is shown when no other formats are available'));
         }
     } else {
         $row['label'] = $this->getLabel($entity);
         $roles = array_map('\\Drupal\\Component\\Utility\\SafeMarkup::checkPlain', filter_get_roles_by_format($entity));
         $roles_markup = $roles ? implode(', ', $roles) : $this->t('No roles may use this format');
     }
     $row['roles'] = !empty($this->weightKey) ? array('#markup' => $roles_markup) : $roles_markup;
     return $row + parent::buildRow($entity);
 }