custom/plugins/MoorlForms/src/Core/Content/Element/Selection/ElementSelectionSalutation.php line 30

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace MoorlForms\Core\Content\Element\Selection;
  3. use MoorlForms\Core\Content\Element\ElementCollection;
  4. use MoorlForms\Core\Content\Element\ElementEntity;
  5. use Shopware\Core\Defaults;
  6. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\NotFilter;
  10. use Shopware\Core\System\Salutation\SalutationEntity;
  11. class ElementSelectionSalutation extends ElementSelectionExtension
  12. {
  13.     protected EntityRepositoryInterface $repository;
  14.     public function __construct(
  15.         EntityRepositoryInterface $repository
  16.     )
  17.     {
  18.         $this->repository $repository;
  19.     }
  20.     public function getName(): string
  21.     {
  22.         return "salutation";
  23.     }
  24.     public function init(ElementEntity $elementElementCollection $elements): void
  25.     {
  26.         $criteria = new Criteria();
  27.         $criteria->addFilter(new NotFilter('or', [
  28.             new EqualsFilter('id'Defaults::SALUTATION),
  29.         ]));
  30.         $items $this->repository->search($criteria$this->salesChannelContext->getContext())->getEntities();
  31.         $newItems = [];
  32.         /** @var SalutationEntity $item */
  33.         foreach ($items as $item) {
  34.             $new $this->createOption($item$element->getId(), $afterId);
  35.             $new->addTranslated('name'$item->getTranslation('displayName'));
  36.             //$new->setTechnicalName($item->getSalutationKey());
  37.             $newItems[] = $new;
  38.         }
  39.         $elements->merge(new ElementCollection($newItems));
  40.     }
  41. }