Loading src/Plugin/EntityReferenceSelection/ViewsSelection.php +20 −3 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\dependent_fields\Plugin\EntityReferenceSelection; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\dependent_fields\Ajax\UpdateOptionsCommand; use Drupal\Component\Utility\Html; use Drupal\Core\Ajax\AjaxResponse; Loading Loading @@ -520,7 +521,14 @@ class ViewsSelection extends PluginBase implements SelectionInterface, Container public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) { $display_name = $this->configuration['dependent_fields_view']['display_name']; $arguments = $this->configuration['dependent_fields_view']['arguments']; $parent_field_value = $this->getParentFieldValue($this->configuration['entity']); $entity = $this->configuration['entity']; if ($entity instanceof FieldableEntityInterface) { $parent_field_value = $this->getParentFieldValue($entity); } else { $parent_field_value = $this->getParentFieldValue(); } if (is_array($parent_field_value) && !empty($parent_field_value['target_id']) && preg_match('/\((\d+)\)$/', $parent_field_value['target_id'], $matches)) { // If the field widget is entity autocomplete, the returned value is a // string which contains the entity id. Loading Loading @@ -564,12 +572,21 @@ class ViewsSelection extends PluginBase implements SelectionInterface, Container public function validateReferenceableEntities(array $ids) { $display_name = $this->configuration['dependent_fields_view']['display_name']; $arguments = $this->configuration['dependent_fields_view']['arguments']; $entity = $this->configuration['entity']; if ($entity instanceof FieldableEntityInterface) { $parent_field_value = $this->getParentFieldValue($entity); } else { $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); Loading @@ -596,7 +613,7 @@ class ViewsSelection extends PluginBase implements SelectionInterface, Container $arguments = $this->configuration['dependent_fields_view']['arguments']; $arguments = !empty($parent_field_value) ? [$parent_field_value] + $arguments : $arguments; $result = []; if ($this->initializeView(NULL, 'CONTAINS', 0)) { if ($this->initializeView()) { // Get the results. $result = $this->view->executeDisplay($display_name, $arguments); } Loading Loading
src/Plugin/EntityReferenceSelection/ViewsSelection.php +20 −3 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\dependent_fields\Plugin\EntityReferenceSelection; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\dependent_fields\Ajax\UpdateOptionsCommand; use Drupal\Component\Utility\Html; use Drupal\Core\Ajax\AjaxResponse; Loading Loading @@ -520,7 +521,14 @@ class ViewsSelection extends PluginBase implements SelectionInterface, Container public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) { $display_name = $this->configuration['dependent_fields_view']['display_name']; $arguments = $this->configuration['dependent_fields_view']['arguments']; $parent_field_value = $this->getParentFieldValue($this->configuration['entity']); $entity = $this->configuration['entity']; if ($entity instanceof FieldableEntityInterface) { $parent_field_value = $this->getParentFieldValue($entity); } else { $parent_field_value = $this->getParentFieldValue(); } if (is_array($parent_field_value) && !empty($parent_field_value['target_id']) && preg_match('/\((\d+)\)$/', $parent_field_value['target_id'], $matches)) { // If the field widget is entity autocomplete, the returned value is a // string which contains the entity id. Loading Loading @@ -564,12 +572,21 @@ class ViewsSelection extends PluginBase implements SelectionInterface, Container public function validateReferenceableEntities(array $ids) { $display_name = $this->configuration['dependent_fields_view']['display_name']; $arguments = $this->configuration['dependent_fields_view']['arguments']; $entity = $this->configuration['entity']; if ($entity instanceof FieldableEntityInterface) { $parent_field_value = $this->getParentFieldValue($entity); } else { $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); Loading @@ -596,7 +613,7 @@ class ViewsSelection extends PluginBase implements SelectionInterface, Container $arguments = $this->configuration['dependent_fields_view']['arguments']; $arguments = !empty($parent_field_value) ? [$parent_field_value] + $arguments : $arguments; $result = []; if ($this->initializeView(NULL, 'CONTAINS', 0)) { if ($this->initializeView()) { // Get the results. $result = $this->view->executeDisplay($display_name, $arguments); } Loading