/** * Inject an input screen into the DCA of a table. * * @param IInputScreen $screen The input screen that shall get injected. * * @return void * * @SuppressWarnings(PHPMD.Superglobals) * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ 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); }); } }
/** * Handle stand alone integration in the backend. * * @param IInputScreen $inputScreen The input screen containing the information. * * @return void */ private function addModuleToBackendMenu($inputScreen) { $metaModel = $inputScreen->getMetaModel(); $moduleName = 'metamodel_' . $metaModel->getTableName(); $tableCaption = $metaModel->getName(); $icon = $this->buildIcon(ToolboxFile::convertValueToPath($inputScreen->getIcon())); $section = $inputScreen->getBackendSection(); if (!$section) { $section = 'metamodels'; } $this->backendMenu[$section][$moduleName] = array('tables' => array($metaModel->getTableName()), 'icon' => $icon, 'callback' => 'MetaModels\\BackendIntegration\\Module'); $caption = array($tableCaption); foreach ($inputScreen->getBackendCaption() as $languageEntry) { if ($languageEntry['langcode'] == 'en') { $caption = array($languageEntry['label'], $languageEntry['description']); } if (!empty($languageEntry['label']) && $languageEntry['langcode'] == $this->viewCombinations->getUser()->language) { $caption = array($languageEntry['label'], $languageEntry['description']); break; } } $this->languageStrings['MOD'][$moduleName] = $caption; }