diff --git a/core/modules/contact/src/Plugin/Block/ContactNavigationBlock.php b/core/modules/contact/src/Plugin/Block/ContactNavigationBlock.php index 6b79758..1b04958 100644 --- a/core/modules/contact/src/Plugin/Block/ContactNavigationBlock.php +++ b/core/modules/contact/src/Plugin/Block/ContactNavigationBlock.php @@ -7,14 +7,14 @@ namespace Drupal\contact\Plugin\Block; -use Drupal\Component\Utility\String; +use Drupal\Component\Utility\Html; +use Drupal\Core\Access\AccessResult; use Drupal\Core\Block\BlockBase; use Drupal\Core\Cache\Cache; use Drupal\Core\Config\Entity\ConfigEntityStorageInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Session\AccountInterface; -use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -79,12 +79,15 @@ public function defaultConfiguration() { * {@inheritdoc} */ public function getCacheTags() { + $cache_tags = parent::getCacheTags(); - if ($forms = array_keys($this->configuration['forms'])) { + $forms = array_keys($this->configuration['forms']); + if ($forms) { foreach ($this->storage->loadMultiple($forms) as $form) { $cache_tags = Cache::mergeTags($cache_tags, $form->getCacheTags()); } } + return $cache_tags; } @@ -103,7 +106,11 @@ protected function getRequiredCacheContexts() { protected function blockAccess(AccountInterface $account) { // Only grant access to users with the 'access site-wide contact form' // permission. - return $account->hasPermission('access site-wide contact form'); + if ($account->hasPermission('access site-wide contact form')) { + return AccessResult::allowed(); + } + + return AccessResult::forbidden(); } /** @@ -148,8 +155,9 @@ public function blockForm($form, FormStateInterface $form_state) { // Find lowest weight to display selected forms first. $min_weight = min($min_weight, $row_weight); } + $row = [ - 'label' => ['#markup' => String::checkPlain($row_label)], + 'label' => ['#markup' => Html::escape($row_label)], 'display' => [ '#type' => 'checkbox', '#default_value' => $row_display, @@ -197,9 +205,11 @@ public function blockValidate($form, FormStateInterface $form_state) { $contact_forms[$id] = $value['weight']; } } + if (empty($contact_forms)) { $form_state->setErrorByName('forms', $this->t('At least one category should be selected.')); } + $form_state->setValue('forms', $contact_forms); } @@ -214,19 +224,21 @@ public function blockSubmit($form, FormStateInterface $form_state) { * {@inheritdoc} */ public function build() { + $links = []; /** @var \Drupal\contact\ContactFormInterface $contact_form */ foreach ($this->storage->loadMultiple(array_keys($this->configuration['forms'])) as $id => $contact_form) { - $links[$id] = $contact_form->link($contact_form->label(), 'submit-form', [ + $links[$id] = $contact_form->link($contact_form->label(), 'canonical', [ 'set_active_class' => TRUE, ]); } + return [ '#theme' => 'item_list__contact', '#items' => $links, '#attributes' => [ 'class' => ['menu'], - ] + ], ]; }