src/EventListener/RenderItemListListener.php
public function handleForItemRendering(ParseItemEvent $event): void
    {
        $settings = $event->getRenderSettings();
        if (!$settings->get(self::FRONTEND_EDITING_ENABLED_FLAG)) {
            return;
        }

        $parsed          = $event->getResult();
        $item            = $event->getItem();
        $tableName       = $item->getMetaModel()->getTableName();
        $definition      = $this->frontendEditor->createDcGeneral($tableName)->getDataDefinition();
        $basicDefinition = $definition->getBasicDefinition();
        $editingPage     = $settings->get(self::FRONTEND_EDITING_PAGE);
        $modelId         = ModelId::fromValues($tableName, $item->get('id'))->getSerialized();

        // Add edit action
        if ($basicDefinition->isEditable()) {
            $parsed['actions']['edit'] = [
                'label' => $this->translateLabel('metamodel_edit_item', $definition->getName()),
                'href'  => $this->generateEditUrl($editingPage, $modelId),
                'class' => 'edit',
            ];
        }

        // Add copy action
        if ($basicDefinition->isCreatable()) {
            $parsed['actions']['copy'] = [
                'label' => $this->translateLabel('metamodel_copy_item', $definition->getName()),
                'href'  => $this->generateCopyUrl($editingPage, $modelId),
                'class' => 'copy',
            ];
        }

        // Add create variant action
        if (false === $item->isVariant() && $basicDefinition->isCreatable() && $item->getMetaModel()->hasVariants()) {
            $parsed['actions']['createvariant'] = [
                'label' => $this->translateLabel('metamodel_create_variant', $definition->getName()),
                'href'  => $this->generateCreateVariantUrl($editingPage, $modelId),
                'class' => 'createvariant',
            ];
        }

        // Add delete action
        if ($basicDefinition->isDeletable()) {
            $parsed['actions']['delete'] = [
                'label'     => $this->translateLabel('metamodel_delete_item', $definition->getName()),
                'href'      => $this->generateDeleteUrl($editingPage, $modelId),
                'attribute' => sprintf(
                    'onclick="if (!confirm(\'%s\')) return false;"',
                    $this->translator->trans('MSC.deleteConfirm', [$item->get('id')], 'contao_default')
                ),
                'class'     => 'delete',
            ];
        }

        $event->setResult($parsed);
    }
public function handleForItemRendering(ParseItemEvent $event): void
    {
        $settings = $event->getRenderSettings();
        if (!$settings->get(self::FRONTEND_EDITING_ENABLED_FLAG)) {
            return;
        }

        $parsed          = $event->getResult();
        $item            = $event->getItem();
        $tableName       = $item->getMetaModel()->getTableName();
        $definition      = $this->frontendEditor->createDcGeneral($tableName)->getDataDefinition();
        $basicDefinition = $definition->getBasicDefinition();
        $editingPage     = $settings->get(self::FRONTEND_EDITING_PAGE);
        $modelId         = ModelId::fromValues($tableName, $item->get('id'))->getSerialized();

        // Add edit action
        if ($basicDefinition->isEditable()) {
            $parsed['actions']['edit'] = [
                'label' => $this->translateLabel('metamodel_edit_item', $definition->getName()),
                'href'  => $this->generateEditUrl($editingPage, $modelId),
                'class' => 'edit',
            ];
        }

        // Add copy action
        if ($basicDefinition->isCreatable()) {
            $parsed['actions']['copy'] = [
                'label' => $this->translateLabel('metamodel_copy_item', $definition->getName()),
                'href'  => $this->generateCopyUrl($editingPage, $modelId),
                'class' => 'copy',
            ];
        }

        // Add create variant action
        if (false === $item->isVariant() && $basicDefinition->isCreatable() && $item->getMetaModel()->hasVariants()) {
            $parsed['actions']['createvariant'] = [
                'label' => $this->translateLabel('metamodel_create_variant', $definition->getName()),
                'href'  => $this->generateCreateVariantUrl($editingPage, $modelId),
                'class' => 'createvariant',
            ];
        }

        // Add delete action
        if ($basicDefinition->isDeletable()) {
            $parsed['actions']['delete'] = [
                'label'     => $this->translateLabel('metamodel_delete_item', $definition->getName()),
                'href'      => $this->generateDeleteUrl($editingPage, $modelId),
                'attribute' => sprintf(
                    'onclick="if (!confirm(\'%s\')) return false;"',
                    $this->translator->trans('MSC.deleteConfirm', [$item->get('id')], 'contao_default')
                ),
                'class'     => 'delete',
            ];
        }

        $event->setResult($parsed);
    }
public function handleForItemRendering ( ParseItemEvent $ event ) : void { $ settings = $ event -> getRenderSettings ( ) ; if ( ! $ settings -> get ( self :: FRONTEND_EDITING_ENABLED_FLAG ) ) { return ; } $ parsed = $ event -> getResult ( ) ; $ item = $ event -> getItem ( ) ; $ tableName = $ item -> getMetaModel ( ) -> getTableName ( ) ; $ definition = $ this -> frontendEditor -> createDcGeneral ( $ tableName ) -> getDataDefinition ( ) ; $ basicDefinition = $ definition -> getBasicDefinition ( ) ; $ editingPage = $ settings -> get ( self :: FRONTEND_EDITING_PAGE ) ; $ modelId = ModelId :: fromValues ( $ tableName , $ item -> get ( 'id' ) ) -> getSerialized ( ) ; // Add edit action if ( $ basicDefinition -> isEditable ( ) ) { $ parsed [ 'actions' ] [ 'edit' ] = [ 'label' => $ this -> translateLabel ( 'metamodel_edit_item' , $ definition -> getName ( ) ) , 'href' => $ this -> generateEditUrl ( $ editingPage , $ modelId ) , 'class' => 'edit' , ] ; } // Add copy action if ( $ basicDefinition -> isCreatable ( ) ) { $ parsed [ 'actions' ] [ 'copy' ] = [ 'label' => $ this -> translateLabel ( 'metamodel_copy_item' , $ definition -> getName ( ) ) , 'href' => $ this -> generateCopyUrl ( $ editingPage , $ modelId ) , 'class' => 'copy' , ] ; } // Add create variant action if ( false === $ item -> isVariant ( ) && $ basicDefinition -> isCreatable ( ) && $ item -> getMetaModel ( ) -> hasVariants ( ) ) { $ parsed [ 'actions' ] [ 'createvariant' ] = [ 'label' => $ this -> translateLabel ( 'metamodel_create_variant' , $ definition -> getName ( ) ) , 'href' => $ this -> generateCreateVariantUrl ( $ editingPage , $ modelId ) , 'class' => 'createvariant' , ] ; } // Add delete action if ( $ basicDefinition -> isDeletable ( ) ) { $ parsed [ 'actions' ] [ 'delete' ] = [ 'label' => $ this -> translateLabel ( 'metamodel_delete_item' , $ definition -> getName ( ) ) , 'href' => $ this -> generateDeleteUrl ( $ editingPage , $ modelId ) , 'attribute' => sprintf ( 'onclick="if (!confirm(\'%s\')) return false;"' , $ this -> translator -> trans ( 'MSC.deleteConfirm' , [ $ item -> get ( 'id' ) ] , 'contao_default' ) ) , 'class' => 'delete' , ] ; } $ event -> setResult ( $ parsed ) ; }
Handle the url injection for item rendering.

@param ParseItemEvent $event The event to process.

@return void
Handle the url injection for item rendering .