You are here

protected function PhpSelection::matchLabel in Drupal 9

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 89

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 = mb_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 mb_substr($label, -mb_strlen($match)) === (string) $match;
    case 'IS NOT NULL':
      return TRUE;
    case 'IS NULL':
      return FALSE;
    default:

      // Invalid match operator.
      return FALSE;
  }
}