&$items) { foreach ($items as $entity_id => $label) { if ($this->matchLabel($match, $match_operator, $label)) { $filtered[$bundle][$entity_id] = $label; $count++; if ($limit && $count >= $limit) { break 2; } } } } return $filtered; } /** * {@inheritdoc} */ public function countReferenceableEntities($match = NULL, $match_operator = 'CONTAINS') { $count = 0; foreach ($this->getReferenceableEntities($match, $match_operator) as &$items) { $count += count($items); } return $count; } /** * Matches an entity label to an input string. * * @param mixed $match * The value to compare. This can be any valid entity query condition value. * @param string $match_operator * The comparison operator. * @param string $label * The entity label to match against. * * @return bool * TRUE when matches, FALSE otherwise. */ 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; } } }