Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / entity_browser / src / Plugin / EntityBrowser / Widget / View.php
index f0aaa19e30ff6d5fc56f8511287af34b6d0d4cc5..111f9b777283151091e98cbbdbd420a5fb1f5171 100644 (file)
@@ -3,6 +3,7 @@
 namespace Drupal\entity_browser\Plugin\EntityBrowser\Widget;
 
 use Drupal\Component\Plugin\Exception\PluginNotFoundException;
+use Drupal\Core\Access\AccessResult;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Render\Element;
 use Drupal\entity_browser\WidgetBase;
@@ -135,7 +136,7 @@ class View extends WidgetBase implements ContainerFactoryPluginInterface {
 
     // When rebuilding makes no sense to keep checkboxes that were previously
     // selected.
-    if (!empty($form['view']['entity_browser_select']) && $form_state->isRebuilding()) {
+    if (!empty($form['view']['entity_browser_select'])) {
       foreach (Element::children($form['view']['entity_browser_select']) as $child) {
         $form['view']['entity_browser_select'][$child]['#process'][] = ['\Drupal\entity_browser\Plugin\EntityBrowser\Widget\View', 'processCheckbox'];
         $form['view']['entity_browser_select'][$child]['#process'][] = ['\Drupal\Core\Render\Element\Checkbox', 'processAjaxForm'];
@@ -158,7 +159,10 @@ class View extends WidgetBase implements ContainerFactoryPluginInterface {
    * @see \Drupal\Core\Render\Element\Checkbox::processCheckbox()
    */
   public static function processCheckbox(&$element, FormStateInterface $form_state, &$complete_form) {
-    $element['#checked'] = FALSE;
+    if ($form_state->isRebuilding()) {
+      $element['#checked'] = FALSE;
+    }
+
     return $element;
   }
 
@@ -279,4 +283,20 @@ class View extends WidgetBase implements ContainerFactoryPluginInterface {
     return $dependencies;
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function access() {
+    // Mark the widget as not visible if the user has no access to the view.
+    /** @var \Drupal\views\ViewExecutable $view */
+    $view = $this->entityTypeManager
+      ->getStorage('view')
+      ->load($this->configuration['view'])
+      ->getExecutable();
+
+
+    // Check if the current user has access to this view.
+    return AccessResult::allowedIf($view->access($this->configuration['view_display']));
+  }
+
 }