private function renderButtonsFor(
        ModelInterface $model,
        ModelInterface $previous = null,
        ModelInterface $next = null
    ) {
        $modelId = ModelId::fromModel($model)->getSerialized();

        if ($this->clipboardItems) {
            $isCircular = \in_array(ModelId::fromModel($model)->getSerialized(), $this->circularModelIds);
        } else {
            $isCircular = false;
        }
        $childIds = $this->getChildIds($model);

        $buttons = [];
        foreach ($this->commands->getCommands() as $command) {
            $buttons[$command->getName()] =
                $this->buildCommand($command, $model, $previous, $next, $isCircular, $childIds);
        }

        if ($this->hasPasteNewButton()) {
            $buttons['pasteNew'] = $this->renderPasteNewFor($modelId);
        }

        // Add paste into/after icons.
        if ($this->hasPasteButtons()) {
            $urlAfter = $this->addToUrl(\sprintf('act=paste&after=%s&', $modelId));
            $urlInto  = $this->addToUrl(\sprintf('act=paste&into=%s&', $modelId));


            $buttonEvent = new GetPasteButtonEvent($this->environment);
            $buttonEvent
                ->setModel($model)
                ->setCircularReference($isCircular)
                ->setPrevious($previous)
                ->setNext($next)
                ->setHrefAfter($urlAfter)
                ->setHrefInto($urlInto)
                // Check if the id is in the ignore list.
                ->setPasteAfterDisabled($isCircular)
                ->setPasteIntoDisabled($isCircular)
                ->setContainedModels($this->clipboardModels);
            $this->eventDispatcher->dispatch(GetPasteButtonEvent::NAME, $buttonEvent);

            $buttons['pasteafter'] = $this->renderPasteAfterButton($buttonEvent);
            if ($this->isHierarchical()) {
                $buttons['pasteinto'] = $this->renderPasteIntoButton($buttonEvent);
            }
        }

        $model->setMeta(
            $model::OPERATION_BUTTONS,
            \implode(' ', $buttons)
        );
    }