src/Contao/View/Contao2BackendView/ButtonRenderer.php
private function buildCommand($command, $model, $previous, $next, $isCircularReference, $childIds)
    {
        $extra      = (array) $command->getExtra();
        $attributes = '';

        if (!empty($extra['attributes'])) {
            $attributes .= \sprintf($extra['attributes'], $model->getID());
        }
        $icon = $extra['icon'];

        if ($command instanceof ToggleCommandInterface) {
            $iconDisabled = ($extra['icon_disabled'] ?? 'invisible.svg');

            $attributes .= \sprintf(
                ' onclick="Backend.getScrollOffset(); return BackendGeneral.toggleVisibility(this, \'%s\', \'%s\');"',
                $icon,
                $iconDisabled
            );

            if (!$this->isTogglerInActiveState($command, $model)) {
                $icon = $iconDisabled;
            }
        }

        $buttonEvent = new GetOperationButtonEvent($this->environment);
        $buttonEvent
            ->setKey($command->getName())
            ->setCommand($command)
            ->setObjModel($model)
            ->setAttributes($attributes)
            ->setLabel($this->getCommandLabel($command))
            ->setTitle(\sprintf($this->translate((string) $command->getDescription()), $model->getID()))
            ->setHref($this->calculateHref($command, $model))
            ->setChildRecordIds($childIds)
            ->setCircularReference($isCircularReference)
            ->setPrevious($previous)
            ->setNext($next)
            ->setDisabled($command->isDisabled());
        $this->eventDispatcher->dispatch(GetOperationButtonEvent::NAME, $buttonEvent);

        if (null !== ($html = $buttonEvent->getHtml())) {
            // If the event created a button, use it.
            return \trim($html);
        }

        if ($buttonEvent->isDisabled()) {
            $iconDisabledSuffix = '_1';

            // Check wheter icon is part of contao
            if ($icon !== Image::getPath($icon)) {
                $iconDisabledSuffix = '_';
            }

            return $this->renderImageAsHtml(
                \substr_replace($icon, $iconDisabledSuffix, \strrpos($icon, '.'), 0),
                $buttonEvent->getLabel()
            );
        }

        return \sprintf(
            ' <a class="%s" href="%s" title="%s" %s>%s</a>',
            $command->getName(),
            $buttonEvent->getHref(),
            StringUtil::specialchars($buttonEvent->getTitle()),
            \ltrim($buttonEvent->getAttributes()),
            $this->renderImageAsHtml($icon, $buttonEvent->getLabel())
        );
    }
private function buildCommand($command, $model, $previous, $next, $isCircularReference, $childIds)
    {
        $extra      = (array) $command->getExtra();
        $attributes = '';

        if (!empty($extra['attributes'])) {
            $attributes .= \sprintf($extra['attributes'], $model->getID());
        }
        $icon = $extra['icon'];

        if ($command instanceof ToggleCommandInterface) {
            $iconDisabled = ($extra['icon_disabled'] ?? 'invisible.svg');

            $attributes .= \sprintf(
                ' onclick="Backend.getScrollOffset(); return BackendGeneral.toggleVisibility(this, \'%s\', \'%s\');"',
                $icon,
                $iconDisabled
            );

            if (!$this->isTogglerInActiveState($command, $model)) {
                $icon = $iconDisabled;
            }
        }

        $buttonEvent = new GetOperationButtonEvent($this->environment);
        $buttonEvent
            ->setKey($command->getName())
            ->setCommand($command)
            ->setObjModel($model)
            ->setAttributes($attributes)
            ->setLabel($this->getCommandLabel($command))
            ->setTitle(\sprintf($this->translate((string) $command->getDescription()), $model->getID()))
            ->setHref($this->calculateHref($command, $model))
            ->setChildRecordIds($childIds)
            ->setCircularReference($isCircularReference)
            ->setPrevious($previous)
            ->setNext($next)
            ->setDisabled($command->isDisabled());
        $this->eventDispatcher->dispatch(GetOperationButtonEvent::NAME, $buttonEvent);

        if (null !== ($html = $buttonEvent->getHtml())) {
            // If the event created a button, use it.
            return \trim($html);
        }

        if ($buttonEvent->isDisabled()) {
            $iconDisabledSuffix = '_1';

            // Check wheter icon is part of contao
            if ($icon !== Image::getPath($icon)) {
                $iconDisabledSuffix = '_';
            }

            return $this->renderImageAsHtml(
                \substr_replace($icon, $iconDisabledSuffix, \strrpos($icon, '.'), 0),
                $buttonEvent->getLabel()
            );
        }

        return \sprintf(
            ' <a class="%s" href="%s" title="%s" %s>%s</a>',
            $command->getName(),
            $buttonEvent->getHref(),
            StringUtil::specialchars($buttonEvent->getTitle()),
            \ltrim($buttonEvent->getAttributes()),
            $this->renderImageAsHtml($icon, $buttonEvent->getLabel())
        );
    }
private function buildCommand ( $ command , $ model , $ previous , $ next , $ isCircularReference , $ childIds ) { $ extra = ( array ) $ command -> getExtra ( ) ; $ attributes = '' ; if ( ! empty ( $ extra [ 'attributes' ] ) ) { $ attributes .= \ sprintf ( $ extra [ 'attributes' ] , $ model -> getID ( ) ) ; } $ icon = $ extra [ 'icon' ] ; if ( $ command instanceof ToggleCommandInterface ) { $ iconDisabled = ( $ extra [ 'icon_disabled' ] ?? 'invisible.svg' ) ; $ attributes .= \ sprintf ( ' onclick="Backend.getScrollOffset(); return BackendGeneral.toggleVisibility(this, \'%s\', \'%s\');"' , $ icon , $ iconDisabled ) ; if ( ! $ this -> isTogglerInActiveState ( $ command , $ model ) ) { $ icon = $ iconDisabled ; } } $ buttonEvent = new GetOperationButtonEvent ( $ this -> environment ) ; $ buttonEvent -> setKey ( $ command -> getName ( ) ) -> setCommand ( $ command ) -> setObjModel ( $ model ) -> setAttributes ( $ attributes ) -> setLabel ( $ this -> getCommandLabel ( $ command ) ) -> setTitle ( \ sprintf ( $ this -> translate ( ( string ) $ command -> getDescription ( ) ) , $ model -> getID ( ) ) ) -> setHref ( $ this -> calculateHref ( $ command , $ model ) ) -> setChildRecordIds ( $ childIds ) -> setCircularReference ( $ isCircularReference ) -> setPrevious ( $ previous ) -> setNext ( $ next ) -> setDisabled ( $ command -> isDisabled ( ) ) ; $ this -> eventDispatcher -> dispatch ( GetOperationButtonEvent :: NAME , $ buttonEvent ) ; if ( null !== ( $ html = $ buttonEvent -> getHtml ( ) ) ) { // If the event created a button, use it. return \ trim ( $ html ) ; } if ( $ buttonEvent -> isDisabled ( ) ) { $ iconDisabledSuffix = '_1' ; // Check wheter icon is part of contao if ( $ icon !== Image :: getPath ( $ icon ) ) { $ iconDisabledSuffix = '_' ; } return $ this -> renderImageAsHtml ( \ substr_replace ( $ icon , $ iconDisabledSuffix , \ strrpos ( $ icon , '.' ) , 0 ) , $ buttonEvent -> getLabel ( ) ) ; } return \ sprintf ( ' <a class="%s" href="%s" title="%s" %s>%s</a>' , $ command -> getName ( ) , $ buttonEvent -> getHref ( ) , StringUtil :: specialchars ( $ buttonEvent -> getTitle ( ) ) , \ ltrim ( $ buttonEvent -> getAttributes ( ) ) , $ this -> renderImageAsHtml ( $ icon , $ buttonEvent -> getLabel ( ) ) ) ; }
Render a command button.

@param CommandInterface $command             The command to render the button for.
@param ModelInterface   $model               The model to which the command shall get applied.
@param ModelInterface   $previous            The previous model in the collection.
@param ModelInterface   $next                The next model in the collection.
@param bool             $isCircularReference Determinator if there exists a circular reference between the model
and the model(s) contained in the clipboard.
@param string[]         $childIds            The ids of all child models.

@return string
Render a command button .