MetaModels\Dca\MetaModelDcaBuilder::injectOperationButton PHP Method

injectOperationButton() public method

Inject an input screen into the DCA of a table.
public injectOperationButton ( MetaModels\BackendIntegration\InputScreen\IInputScreen $screen ) : void
$screen MetaModels\BackendIntegration\InputScreen\IInputScreen The input screen that shall get injected.
return void
    public function injectOperationButton($screen)
    {
        $parentTable = $screen->getParentTable();
        $parentDCA =& $GLOBALS['TL_DCA'][$parentTable];
        $dispatcher = $this->getDispatcher();
        $metaModel = $screen->getMetaModel();
        $event = new LoadLanguageFileEvent('default');
        $dispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, $event);
        $arrCaption = array(sprintf($GLOBALS['TL_LANG']['MSC']['metamodel_edit_as_child']['label'], $metaModel->getName()), '');
        foreach ($screen->getBackendCaption() as $arrLangEntry) {
            if ($arrLangEntry['label'] != '' && $arrLangEntry['langcode'] == $GLOBALS['TL_LANGUAGE']) {
                $arrCaption = array($arrLangEntry['label'], $arrLangEntry['description']);
            }
        }
        $parentDCA['list']['operations']['edit_' . $metaModel->getTableName()] = array('label' => &$arrCaption, 'href' => 'table=' . $metaModel->getTableName(), 'icon' => $this->getBackendIcon($screen->getIcon()), 'attributes' => 'onclick="Backend.getScrollOffset()"');
        $operationName = 'edit_' . $metaModel->getTableName();
        // Is the destination table a metamodel with variants?
        if ($metaModel->hasVariants()) {
            $parentDCA['list']['operations'][$operationName]['idparam'] = 'id_' . $parentTable;
        } else {
            $parentDCA['list']['operations'][$operationName]['idparam'] = 'pid';
        }
        // Compatibility with DC_Table.
        if ($parentDCA['config']['dataContainer'] !== 'General') {
            $handler = $this;
            $idParameter = $parentDCA['list']['operations'][$operationName]['idparam'];
            $parentDCA['list']['operations'][$operationName]['button_callback'] = OperationButtonCallbackListener::generateFor($parentTable, $operationName, function ($row, $href, $label, $name, $icon, $attributes, $table) use($handler, $idParameter) {
                return $handler->buildChildOperationButton($idParameter, $row, $href, $label, $name, $icon, $attributes, $table);
            });
        }
    }

Usage Example

Ejemplo n.º 1
0
Archivo: Boot.php Proyecto: zonky2/core
 /**
  * Boot the system in the backend.
  *
  * @param MetaModelsBootEvent $event The event.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 public function perform(MetaModelsBootEvent $event)
 {
     $container = $event->getServiceContainer();
     $viewCombinations = new ViewCombinations($container, $GLOBALS['container']['user']);
     $container->setService($viewCombinations, 'metamodels-view-combinations');
     $menuBuilder = new BackendModuleBuilder($container, $viewCombinations);
     $menuBuilder->export();
     // Prepare lazy loading of the data containers.
     foreach ($viewCombinations->getParentedInputScreenNames() as $metaModelName) {
         $parent = $viewCombinations->getParentOf($metaModelName);
         if (substr($parent, 0, 3) === 'mm_') {
             continue;
         }
         LoadDataContainerHookListener::attachFor($parent, function () use($metaModelName, $viewCombinations, $container) {
             $inputScreen = $viewCombinations->getInputScreenDetails($metaModelName);
             $builder = new MetaModelDcaBuilder($container);
             $builder->injectOperationButton($inputScreen);
         });
     }
     $dispatcher = $container->getEventDispatcher();
     foreach ($container->getFactory()->collectNames() as $metaModelName) {
         $this->attachLoadDataContainerHook($metaModelName, $container);
         $dispatcher->addListener(PreCreateDcGeneralEvent::NAME, function (PreCreateDcGeneralEvent $event) use($metaModelName, $viewCombinations, $container) {
             $factory = $event->getFactory();
             $name = $factory->getContainerName();
             if ($name !== $metaModelName) {
                 return;
             }
             $inputScreen = $viewCombinations->getInputScreenDetails($metaModelName);
             $factory->setContainerClassName('MetaModels\\DcGeneral\\DataDefinition\\MetaModelDataDefinition');
             $dispatcher = $container->getEventDispatcher();
             $generator = new Builder($container, $inputScreen);
             $dispatcher->addListener(BuildDataDefinitionEvent::NAME, function (BuildDataDefinitionEvent $event) use($metaModelName, $generator) {
                 if ($event->getContainer()->getName() !== $metaModelName) {
                     return;
                 }
                 $generator->build($event);
             }, $generator::PRIORITY);
             $dispatcher->addListener(PopulateEnvironmentEvent::NAME, function (PopulateEnvironmentEvent $event) use($metaModelName, $generator) {
                 if ($event->getEnvironment()->getDataDefinition()->getName() !== $metaModelName) {
                     return;
                 }
                 $generator->populate($event);
                 $GLOBALS['TL_CSS'][] = 'system/modules/metamodels/assets/css/style.css';
             }, $generator::PRIORITY);
         });
     }
     // Register the global subscriber.
     new Subscriber($container);
     $this->overrideFilePicker();
 }