Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * 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);
         });
     }
 }
Пример #3
0
 /**
  * Build the property information for a certain property from the data container array.
  *
  * @param PropertiesDefinitionInterface $definition  The property collection definition.
  *
  * @param string                        $propName    The name of the property.
  *
  * @param IInputScreen                  $inputScreen The input screen instance.
  *
  * @return void
  */
 protected function buildPropertyFromDca(PropertiesDefinitionInterface $definition, $propName, IInputScreen $inputScreen)
 {
     $property = $inputScreen->getProperty($propName);
     $propInfo = $property['info'];
     $metaModel = $this->getMetaModel();
     $attribute = $metaModel->getAttribute($propName);
     if (!$attribute) {
         return;
     }
     $isTranslated = $metaModel->isTranslated() && $attribute instanceof ITranslated;
     if ($definition->hasProperty($propName)) {
         $property = $definition->getProperty($propName);
     } else {
         $property = new DefaultProperty($propName);
         $definition->addProperty($property);
     }
     if (!$property->getLabel() && isset($propInfo['label'])) {
         $lang = $propInfo['label'];
         if (is_array($lang)) {
             $label = reset($lang);
             $description = next($lang);
             $property->setDescription($description);
         } else {
             $label = $lang;
         }
         $property->setLabel($label);
     }
     if (!$property->getDescription() && isset($propInfo['description'])) {
         $property->setDescription($propInfo['description']);
     }
     if (!$property->getDefaultValue() && isset($propInfo['default'])) {
         $property->setDefaultValue($propInfo['default']);
     }
     if (isset($propInfo['exclude'])) {
         $property->setExcluded($propInfo['exclude']);
     }
     if (isset($propInfo['search'])) {
         $property->setSearchable($propInfo['search']);
     }
     if (isset($propInfo['filter'])) {
         $property->setFilterable($propInfo['filter']);
     }
     if (!$property->getWidgetType() && isset($propInfo['inputType'])) {
         $property->setWidgetType($propInfo['inputType']);
     }
     if (!$property->getOptions() && isset($propInfo['options'])) {
         $property->setOptions($propInfo['options']);
     }
     if (!$property->getExplanation() && isset($propInfo['explanation'])) {
         $property->setExplanation($propInfo['explanation']);
     }
     if (isset($propInfo['eval'])) {
         $extra = $propInfo['eval'];
         if ($isTranslated) {
             $extra['tl_class'] = 'translat-attr' . (!empty($extra['tl_class']) ? ' ' . $extra['tl_class'] : '');
         }
         $property->setExtra(array_merge((array) $property->getExtra(), $extra));
     }
 }