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())
        );
    }