You are here

protected function PhpSelection::matchLabel in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/PhpSelection.php \Drupal\Core\Entity\Plugin\EntityReferenceSelection\PhpSelection::matchLabel()

Matches an entity label to an input string.

Parameters

mixed $match: The value to compare. This can be any valid entity query condition value.

string $match_operator: The comparison operator.

string $label: The entity label to match against.

Return value

bool TRUE when matches, FALSE otherwise.

1 call to PhpSelection::matchLabel()
PhpSelection::getReferenceableEntities in core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/PhpSelection.php
Gets the list of referenceable entities.

File

core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/PhpSelection.php, line 95
Contains \Drupal\Core\Entity\Plugin\EntityReferenceSelection\PhpSelection.

Class

PhpSelection
Defines an alternative to the default Entity Reference Selection plugin.

Namespace

Drupal\Core\Entity\Plugin\EntityReferenceSelection

Code

protected function matchLabel($match, $match_operator, $label) {

  // Always use a case-insensitive value.
  $label = Unicode::strtolower($label);
  switch ($match_operator) {
    case '=':
      return $label == $match;
    case '>':
      return $label > $match;
    case '<':
      return $label < $match;
    case '>=':
      return $label >= $match;
    case '<=':
      return $label <= $match;
    case '<>':
      return $label != $match;
    case 'IN':
      return array_search($label, $match) !== FALSE;
    case 'NOT IN':
      return array_search($label, $match) === FALSE;
    case 'STARTS_WITH':
      return strpos($label, $match) === 0;
    case 'CONTAINS':
      return strpos($label, $match) !== FALSE;
    case 'ENDS_WITH':
      return Unicode::substr($label, -Unicode::strlen($match)) === (string) $match;
    case 'IS NOT NULL':
      return TRUE;
    case 'IS NULL':
      return FALSE;
    default:

      // Invalid match operator.
      return FALSE;
  }
}