Commit c26bbc16 authored by Andrii Podanenko's avatar Andrii Podanenko
Browse files

Issue #3100599 by caspervoogt, Kakarotu, podarok, svendecabooter: Unpublished...

Issue #3100599 by caspervoogt, Kakarotu, podarok, svendecabooter: Unpublished content should show nothing in options instead of showing "Restricted Access"
parent 21061213
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -24,7 +24,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 *
 * @ViewsFilter("verf")
 */
class EntityReference extends InOperator implements ContainerFactoryPluginInterface {
class EntityReference extends InOperator implements ContainerFactoryPluginInterface
{

  /**
   * The entity type bundle info.
@@ -108,6 +109,10 @@ class EntityReference extends InOperator implements ContainerFactoryPluginInterf
      'default' => [],
    ];

    $options['show_unpublished'] = [
      'default' => FALSE,
    ];

    return $options;
  }

@@ -116,6 +121,13 @@ class EntityReference extends InOperator implements ContainerFactoryPluginInterf
   */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);

    $form['show_unpublished'] = [
      '#type' => 'checkbox',
      '#title' => t("Ignore access control"),
      '#default_value' => $this->options['show_unpublished'],
    ];

    if (!$this->targetEntityType->hasKey('bundle')) {
      return $form;
    }
@@ -197,6 +209,17 @@ class EntityReference extends InOperator implements ContainerFactoryPluginInterf
    }

    $this->referenceableEntities = $this->targetEntityStorage->loadMultiple($target_ids);

    if (!$this->options['show_unpublished']) {
      $filtered_target_ids = [];
      foreach ($this->referenceableEntities as $entity) {
        if ($entity->access('view')) {
          $filtered_target_ids[] = $entity;
        }
      }
      $this->referenceableEntities = $filtered_target_ids;
    }

    return $this->referenceableEntities;
  }