You are here

protected function BusinessRulesViewsSelection::getParentFieldValue 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::getParentFieldValue()

Get the parent field value.

Parameters

\Drupal\Core\Entity\Entity|NULL $entity: The fallback entity to extract the value from.

Return value

mixed The parent field value.

2 calls to BusinessRulesViewsSelection::getParentFieldValue()
BusinessRulesViewsSelection::getReferenceableEntities in src/Plugin/EntityReferenceSelection/BusinessRulesViewsSelection.php
Gets the list of referenceable entities.
BusinessRulesViewsSelection::validateReferenceableEntities in src/Plugin/EntityReferenceSelection/BusinessRulesViewsSelection.php
Validates which existing entities can be referenced.

File

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

Class

BusinessRulesViewsSelection
Plugin override of the 'selection' entity_reference.

Namespace

Drupal\business_rules\Plugin\EntityReferenceSelection

Code

protected function getParentFieldValue(EntityInterface $entity = NULL) {
  $handler_settings = $this
    ->getHandlerSettings();
  $field = $handler_settings['business_rules_view']['parent_field'];
  $value = $this->util->request
    ->get($field);
  if (!$value && $entity && $entity
    ->get($field)) {
    $value = $entity
      ->get($field)
      ->getString();
  }
  if (is_array($value) && !empty($value[0]['target_id']) && preg_match('/\\((\\d+)\\)$/', $value[0]['target_id'], $matches)) {

    // If the field widget is entity autocomplete, the returned value is a
    // string which contains the entity id.
    $value = $matches[1];
  }
  return $value;
}