function PhpSelection::matchLabel

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/PhpSelection.php \Drupal\Core\Entity\Plugin\EntityReferenceSelection\PhpSelection::matchLabel()
  2. 8.9.x core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/PhpSelection.php \Drupal\Core\Entity\Plugin\EntityReferenceSelection\PhpSelection::matchLabel()
  3. 10 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

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 str_starts_with($label, $match);
        case 'CONTAINS':
            return str_contains($label, $match);
        case 'ENDS_WITH':
            return str_ends_with($label, $match);
        case 'IS NOT NULL':
            return TRUE;
        case 'IS NULL':
            return FALSE;
        default:
            // Invalid match operator.
            return FALSE;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.