getMatches example

$entity_type_id = $request->query->get('entity_type');
      if ($entity_type_id && $this->entityTypeManager()->hasDefinition($entity_type_id)) {
        $entity_id = $request->query->get('entity_id');
        if ($entity_id) {
          $entity = $this->entityTypeManager()->getStorage($entity_type_id)->load($entity_id);
          if ($entity->access('update')) {
            $selection_settings['entity'] = $entity;
          }
        }
      }

      $matches = $this->matcher->getMatches($target_type$selection_handler$selection_settings$typed_string);
    }

    return new JsonResponse($matches);
  }

}
$user2 = $this->createUser([], 'aabbb');
    $user2->addRole($this->role1->id());
    $user2->save();

    $user3 = $this->createUser([], 'aabbbb');
    $user3->addRole($this->role2->id());
    $user3->save();

    /** @var \Drupal\Core\Entity\EntityAutocompleteMatcherInterface $autocomplete */
    $autocomplete = \Drupal::service('entity.autocomplete_matcher');

    $matches = $autocomplete->getMatches('user', 'default', $field_definition->getSetting('handler_settings'), 'aabb');
    $this->assertCount(2, $matches);
    $users = [];
    foreach ($matches as $match) {
      $users[] = $match['label'];
    }
    $this->assertContains($user1->label()$users);
    $this->assertContains($user2->label()$users);
    $this->assertNotContains($user3->label()$users);

    $matches = $autocomplete->getMatches('user', 'default', $field_definition->getSetting('handler_settings'), 'aabbbb');
    $this->assertCount(0, $matches);
  }

    public function filter($selector)
    {
        $parser = new Selector\Parser($selector$this->options);
        $selector = $parser->parse(true);
        $this->matches->filter(function D$node$parent) use ($selector) {
            $newMatch = new Selector\Matches();
            $newMatch->addMatch($node$parent);
            return $selector->exec($newMatch)->getMatches();
        });
        return $this;
    }

    /** * Returns the number of matched nodes * * @return int */
    #[\ReturnTypeWillChange]     public function count()
    {


namespace Shopware\Bundle\MailBundle\AutocompleteResolver;

class ForeachResolver extends AbstractResolver
{
    private const FOREACH_REGEX = '/{foreach\s+\w+=[a-zA-Z0-9\$](.*)}/m';
    private const ATTR_REGEX = '/(\s*(?<key>\w+)=(?<value>[a-zA-Z0-9\$]+)\s*)/';

    public function completer(array $context, string $smartyCode): array
    {
        foreach ($this->getMatches($smartyCode) as $match) {
            if (!isset($match['from']$match['item'])) {
                continue;
            }

            $value = $this->getValueFromPath($context$match['from']);

            if ($value === null) {
                continue;
            }

            $count = \count($value);

            
protected function matchZipCode(CustomerAddressEntity $address): bool
    {
        $zipCode = $this->sanitizeZipCode($address);

        if ($this->zipCodes === null && $this->operator !== self::OPERATOR_EMPTY) {
            throw new UnsupportedValueException(\gettype($this->zipCodes), self::class);
        }

        $compareZipCode = \is_array($this->zipCodes) ? $this->zipCodes[0] : null;

        return match ($this->operator) {
            Rule::OPERATOR_EQ => !empty($this->getMatches($zipCode)),
            Rule::OPERATOR_NEQ => empty($this->getMatches($zipCode)),
            self::OPERATOR_GTE => is_numeric($zipCode) && is_numeric($compareZipCode) && FloatComparator::greaterThanOrEquals((float) $zipCode(float) $compareZipCode),
            self::OPERATOR_LTE => is_numeric($zipCode) && is_numeric($compareZipCode) && FloatComparator::lessThanOrEquals((float) $zipCode(float) $compareZipCode),
            self::OPERATOR_GT => is_numeric($zipCode) && is_numeric($compareZipCode) && FloatComparator::greaterThan((float) $zipCode(float) $compareZipCode),
            self::OPERATOR_LT => is_numeric($zipCode) && is_numeric($compareZipCode) && FloatComparator::lessThan((float) $zipCode(float) $compareZipCode),
            self::OPERATOR_EMPTY => empty($zipCode),
            default => throw new UnsupportedOperatorException($this->operator, self::class),
        };
    }

    /** * @return array<string> */
/** * Merges the current object with the other given Matches objects * * @param Matches[] $matchesArr Array of Matches to merge * * @return $this */
    public function merge($matchesArr)
    {
        foreach ($matchesArr as $matches) {
            foreach ($matches->getMatches() as $match) {
                $this->addMatch($match[0]$match[1]);
            }
        }
        return $this->unique();
    }

    /** * Remove all duplicated matches * * @return $this */
    
Home | Imprint | This part of the site doesn't use cookies.