You are here

public function BusinessRulesViewsSelection::validateReferenceableEntities in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Plugin/EntityReferenceSelection/BusinessRulesViewsSelection.php \Drupal\business_rules\Plugin\EntityReferenceSelection\BusinessRulesViewsSelection::validateReferenceableEntities()

Validates which existing entities can be referenced.

Return value

array An array of valid entity IDs.

Overrides SelectionInterface::validateReferenceableEntities

File

src/Plugin/EntityReferenceSelection/BusinessRulesViewsSelection.php, line 466

Class

BusinessRulesViewsSelection
Plugin override of the 'selection' entity_reference.

Namespace

Drupal\business_rules\Plugin\EntityReferenceSelection

Code

public function validateReferenceableEntities(array $ids) {
  $handler_settings = $this
    ->getHandlerSettings();
  $display_name = $handler_settings['business_rules_view']['display_name'];
  $arguments = $handler_settings['business_rules_view']['arguments'];
  $parent_field_value = $this
    ->getParentFieldValue();

  // If we have an array with values we should implode those values and enable
  // Allow multiple values into our contextual filter.
  if (is_array($parent_field_value)) {
    $parent_field_value = implode(",", $parent_field_value);
  }
  $arguments = !empty($parent_field_value) ? [
    $parent_field_value,
  ] + $arguments : $arguments;
  $result = [];
  $ids = $this
    ->getValidIds($parent_field_value);
  if ($this
    ->initializeView(NULL, 'CONTAINS', 0, $ids)) {

    // Get the results.
    $entities = $this->view
      ->executeDisplay($display_name, $arguments);
    $result = is_array($entities) ? array_keys($entities) : [];
  }
  return $result;
}