/** * Register component * * @return void */ public function prepare() { $namespace = $this->getContext()->getRequestParam('namespace', $this->getContext()->getNamespace()); $config = []; if (!empty($namespace)) { $bookmarks = $this->bookmarkManagement->loadByNamespace($namespace); /** @var \Magento\Ui\Api\Data\BookmarkInterface $bookmark */ foreach ($bookmarks->getItems() as $bookmark) { if ($bookmark->isCurrent()) { $config['activeIndex'] = $bookmark->getIdentifier(); } $config = array_merge_recursive($config, $bookmark->getConfig()); } } $this->setData('config', array_replace_recursive($config, $this->getConfiguration($this))); parent::prepare(); $jsConfig = $this->getConfiguration($this); $this->getContext()->addComponentDefinition($this->getComponentName(), $jsConfig); }
/** * Update current bookmark * * @param string $identifier * @return void */ protected function updateCurrentBookmark($identifier) { $bookmarks = $this->bookmarkManagement->loadByNamespace($this->_request->getParam('namespace')); foreach ($bookmarks->getItems() as $bookmark) { if ($bookmark->getIdentifier() == $identifier) { $bookmark->setCurrent(true); } else { $bookmark->setCurrent(false); } $this->bookmarkRepository->save($bookmark); } }
/** * Update bookmarks based on request params * * @param BookmarkInterface $bookmark * @param string $identifier * @param string $title * @param array $config * @return void */ protected function updateBookmark(BookmarkInterface $bookmark, $identifier, $title, array $config = []) { $this->filterVars($config); $bookmark->setUserId($this->userContext->getUserId())->setNamespace($this->_request->getParam('namespace'))->setIdentifier($identifier)->setTitle($title)->setConfig($config)->setCurrent($identifier !== self::CURRENT_IDENTIFIER); $this->bookmarkRepository->save($bookmark); $bookmarks = $this->bookmarkManagement->loadByNamespace($this->_request->getParam('namespace')); foreach ($bookmarks->getItems() as $bookmark) { if ($bookmark->getIdentifier() == $identifier) { continue; } $bookmark->setCurrent(false); $this->bookmarkRepository->save($bookmark); } }