Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MultisuggestElement.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Client\Locator;
10 
15 {
21  protected $categoryChoice = '//div[contains(@data-index, "category_ids")]';
22 
28  protected $choice = './/li/div[text()="%s"]/..';
29 
35  protected $choiceValue = './/span[contains(@class,"admin__action-multiselect-crumb")]/span';
36 
42  protected $choiceClose = '[data-action="remove-selected-item"]';
43 
50  public function setValue($values)
51  {
52  $this->eventManager->dispatchEvent(['set_value'], [__METHOD__, $this->getAbsoluteSelector()]);
53 
54  $this->clear();
55  foreach ((array)$values as $value) {
56  if (!$this->isChoice($value)) {
57  parent::setValue($value);
58  }
59  }
60  }
61 
67  public function getValue()
68  {
69  $this->eventManager->dispatchEvent(['get_value'], [(string) $this->getAbsoluteSelector()]);
70 
71  $categoryChoice = $this->find($this->categoryChoice, Locator::SELECTOR_XPATH);
72  $choices = $categoryChoice->getElements($this->choiceValue, Locator::SELECTOR_XPATH);
73  $values = [];
74 
75  foreach ($choices as $choice) {
77  $values[] = $choice->getText();
78  }
79  return $values;
80  }
81 
88  protected function isChoice($value)
89  {
90  return $this->find(sprintf($this->choice, $value), Locator::SELECTOR_XPATH)->isVisible();
91  }
92 
98  protected function clear()
99  {
100  $choiceClose = $this->find($this->choiceClose);
101  while ($choiceClose->isVisible()) {
102  $choiceClose->click();
103  $choiceClose = $this->find($this->choiceClose);
104  }
105  }
106 }
taxRateField find('.mselect-list') .on( 'click.mselect-edit'
Definition: edit.phtml:162
$values
Definition: options.phtml:88
$value
Definition: gender.phtml:16