예제 #1
0
 /**
  * @return $this
  */
 protected function _prepareCollection()
 {
     $collection = $this->categoryCollectionFactory->create();
     $collection = $collection->addAttributeToSelect('*');
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
예제 #2
0
 /**
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function _prepareLayout()
 {
     parent::_prepareLayout();
     $category = $this->getCategory();
     $title = $category ? $category->getName() : $this->config->getBlogName();
     $metaTitle = $category ? $category->getMetaTitle() ? $category->getMetaTitle() : $category->getName() : $this->config->getBaseMetaTitle();
     $metaDescription = $category ? $category->getMetaDescription() ? $category->getMetaDescription() : $category->getName() : $this->config->getBaseMetaDescription();
     $metaKeywords = $category ? $category->getMetaKeywords() ? $category->getMetaKeywords() : $category->getName() : $this->config->getBaseMetaKeywords();
     $this->pageConfig->getTitle()->set($metaTitle);
     $this->pageConfig->setDescription($metaDescription);
     $this->pageConfig->setKeywords($metaKeywords);
     /** @var \Magento\Theme\Block\Html\Title $pageMainTitle */
     $pageMainTitle = $this->getLayout()->getBlock('page.main.title');
     if ($pageMainTitle) {
         $pageMainTitle->setPageTitle($title);
     }
     /** @var \Magento\Theme\Block\Html\Breadcrumbs $breadcrumbs */
     if ($breadcrumbs = $this->getLayout()->getBlock('breadcrumbs')) {
         $breadcrumbs->addCrumb('home', ['label' => __('Home'), 'title' => __('Go to Home Page'), 'link' => $this->context->getUrlBuilder()->getBaseUrl()])->addCrumb('blog', ['label' => $this->config->getBlogName(), 'title' => $this->config->getBlogName(), 'link' => $this->config->getBaseUrl()]);
         if ($category) {
             $ids = $category->getParentIds();
             $ids[] = 0;
             $parents = $this->categoryCollectionFactory->create()->addFieldToFilter('entity_id', $ids)->addNameToSelect()->excludeRoot()->setOrder('level', 'asc');
             /** @var \Mirasvit\Blog\Model\Category $cat */
             foreach ($parents as $cat) {
                 $breadcrumbs->addCrumb($cat->getId(), ['label' => $cat->getName(), 'title' => $cat->getName(), 'link' => $cat->getUrl()]);
             }
             $breadcrumbs->addCrumb($category->getId(), ['label' => $category->getName(), 'title' => $category->getName()]);
         }
     }
     return $this;
 }
예제 #3
0
 /**
  * @return $this
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _prepareForm()
 {
     $form = $this->formFactory->create();
     $this->setForm($form);
     /** @var \Mirasvit\Blog\Model\Post $post */
     $post = $this->registry->registry('current_model');
     $fieldset = $form->addFieldset('categories_fieldset', ['class' => 'blog__post-fieldset', 'legend' => __('Categories')]);
     $collection = $this->categoryCollectionFactory->create()->addAttributeToSelect(['name']);
     $fieldset->addField('category_ids', 'checkboxes', ['name' => 'post[category_ids][]', 'value' => $post->getCategoryIds(), 'values' => $collection->toOptionArray()]);
     return parent::_prepareForm();
 }
예제 #4
0
 /**
  * @return $this
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _prepareForm()
 {
     $form = $this->formFactory->create();
     $this->setForm($form);
     /** @var \Mirasvit\Blog\Model\Category $category */
     $category = $this->registry->registry('current_model');
     $fieldset = $form->addFieldset('edit_fieldset', ['legend' => __('General Information')]);
     if ($category->getId()) {
         $fieldset->addField('entity_id', 'hidden', ['name' => 'entity_id', 'value' => $category->getId()]);
     }
     $fieldset->addField('name', 'text', ['label' => __('Title'), 'name' => 'name', 'value' => $category->getName(), 'required' => true]);
     if ($category->getId() != 1) {
         $categories = $this->categoryCollectionFactory->create()->addAttributeToSelect('name')->toOptionArray();
         $fieldset->addField('parent_id', 'radios', ['label' => __('Parent Category'), 'name' => 'parent_id', 'value' => $category->getParentId() ? $category->getParentId() : 1, 'values' => $categories, 'required' => true]);
     }
     $fieldset->addField('status', 'select', ['label' => __('Status'), 'name' => 'status', 'value' => $category->getStatus(), 'values' => ['0' => __('Disabled'), '1' => __('Enabled')]]);
     return parent::_prepareForm();
 }
예제 #5
0
 /**
  * {@inheritdoc}
  *
  * @param EventObserver $observer
  */
 public function execute(EventObserver $observer)
 {
     /** @var \Magento\Framework\Data\Tree\Node $menu */
     $menu = $observer->getData('menu');
     $categories = $this->categoryCollectionFactory->create()->addAttributeToSelect(['name', 'url_key'])->excludeRoot()->addVisibilityFilter();
     $tree = $categories->getTree();
     $rootNode = new TreeNode(['id' => 'blog-node-root', 'name' => $this->config->getMenuTitle(), 'url' => $this->config->getBaseUrl()], 'id', $menu->getTree(), null);
     $menu->addChild($rootNode);
     foreach ($tree as $category) {
         if (isset($tree[$category->getParentId()])) {
             $parentNode = $tree[$category->getParentId()]->getData('node');
         } else {
             $parentNode = $rootNode;
         }
         $node = new TreeNode(['id' => 'blog-node-' . $category->getId(), 'name' => $category->getName(), 'url' => $category->getUrl()], 'id', $menu->getTree(), $parentNode);
         if ($parentNode) {
             $parentNode->addChild($node);
         } else {
             $menu->addChild($node);
         }
         $category->setData('node', $node);
     }
 }
예제 #6
0
 /**
  * @return \Mirasvit\Blog\Model\Category[]
  */
 public function getTree()
 {
     return $this->categoryCollectionFactory->create()->addAttributeToSelect(['name', 'url_key'])->addVisibilityFilter()->excludeRoot()->getTree();
 }