N
N
Nikolai Gromov2018-04-27 05:57:46
PHP
Nikolai Gromov, 2018-04-27 05:57:46

What is the correct class for a tag?

Good day.
Tell me why the class for the tag I prescribed does not reach the view. This part of the code specifies the configuration for the menu items.<a>

'navigation' => [
        'Application\Navigation\MainNavigation' => [
            'application' => [
                /**
                 * Set options for 'ul'-element.
                 * For correct set - page must have most lowest order number (e.g. -100).
                 */
                'ul' => ['class' => 'navbar-nav  align-content-between'],
                'li' => ['class' => 'nav-item m-auto'],

                /** Set attributes for 'a'-element. */
                'a'  => ['class' => 'nav-link'],
                'label' => 'Главная',

                /** Set options for element. */
                'order'      => 10,
                'route'      => 'home',
                'action'     => 'index',
                'controller' => Controller\IndexController::class,
            ],

And this part of the code is responsible for processing the tag<a>
public function htmlify(AbstractPage $page, $escapeLabel = true, $addClassToListItem = false)
    {
        // get attribs for element
        $attribs = [
            'id'     => $page->getId(),
            'title'  => $this->translate($page->getTitle(), $page->getTextDomain()),
        ];
/**
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Begin fork ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 * @since 18:37 30.10.2016
 */
        // add additional attributes
        $attr = $page->get('attr');
        if(is_array($attr)){
            $attribs = $attribs + $attr;
        };
/**
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ End fork ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */
        if ($addClassToListItem === false) {
            $attribs['class'] = $page->getClass();
        }

        // does page have a href?
        $href = $page->getHref();
        if ($href) {
            $element           = 'a';
            $attribs['href']   = $href;
            $attribs['target'] = $page->getTarget();
        } else {
            $element = 'span';
        }

        $html  = '<' . $element . $this->htmlAttribs($attribs) . '>';
        $label = $this->translate($page->getLabel(), $page->getTextDomain());

        if ($escapeLabel === true) {
            /** @var \Zend\View\Helper\EscapeHtml $escaper */
            $escaper = $this->view->plugin('escapeHtml');
            $html .= $escaper($label);
        } else {
            $html .= $label;
        }

        $html .= '</' . $element . '>';
        return $html;
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Levchenko, 2018-04-27
@T_verdisla_V

think you need to do
$addClassToListItem = true

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question