Ejemplo n.º 1
0
 /**
  * Draw the render setting.
  *
  * @param ModelToLabelEvent $event The event.
  *
  * @return void
  */
 public function modelToLabel(ModelToLabelEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_dca_sortgroup') {
         return;
     }
     if ($event->getModel()->getProperty('isdefault')) {
         $event->setLabel(sprintf('%s <span style="color:#b3b3b3; padding-left:3px">[%s]</span>', $event->getLabel(), $event->getEnvironment()->getTranslator()->translate('MSC.fallback')));
     }
 }
Ejemplo n.º 2
0
 /**
  * Render the current item using the specified render setting.
  *
  * @param ModelToLabelEvent $event The event.
  *
  * @return void
  */
 public static function render(ModelToLabelEvent $event)
 {
     $environment = $event->getEnvironment();
     /** @var IMetaModelDataDefinition $definition */
     $definition = $environment->getDataDefinition();
     /** @var Contao2BackendViewDefinitionInterface $viewSection */
     $viewSection = $definition->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
     $listing = $viewSection->getListingConfig();
     /** @var Model $model */
     $model = $event->getModel();
     if (!$model instanceof Model) {
         return;
     }
     $nativeItem = $model->getItem();
     $metaModel = $nativeItem->getMetaModel();
     $renderSetting = $metaModel->getServiceContainer()->getRenderSettingFactory()->createCollection($metaModel, $definition->getMetaModelDefinition()->getActiveRenderSetting());
     if (!$renderSetting) {
         return;
     }
     $data = array($nativeItem->parseValue('html5', $renderSetting));
     if ($listing->getShowColumns()) {
         $event->setArgs($data[0]['html5']);
         return;
     }
     $template = new Template($renderSetting->get('template'));
     $renderSetting = self::removeInvariantAttributes($nativeItem, $renderSetting);
     $template->setData(array('settings' => $renderSetting, 'items' => new Items(array($nativeItem)), 'view' => $renderSetting, 'data' => $data));
     $event->setArgs(array($template->parse('html5')));
 }
Ejemplo n.º 3
0
 /**
  * Draw the render setting.
  *
  * @param ModelToLabelEvent $event The event.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 public function modelToLabel(ModelToLabelEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_rendersettings') {
         return;
     }
     if ($event->getModel()->getProperty('isdefault')) {
         $event->setLabel($event->getLabel() . ' <span style="color:#b3b3b3; padding-left:3px">[' . $GLOBALS['TL_LANG']['MSC']['fallback'] . ']</span>');
     }
 }
Ejemplo n.º 4
0
 /**
  * Render the html for the input screen.
  *
  * @param ModelToLabelEvent $event The event.
  *
  * @return void
  */
 public function modelToLabel(ModelToLabelEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_dca') {
         return;
     }
     $environment = $event->getEnvironment();
     $translator = $environment->getTranslator();
     $model = $event->getModel();
     if (!$model->getProperty('isdefault')) {
         return;
     }
     $event->setArgs(array_merge($event->getArgs(), array($translator->translate('MSC.fallback'))))->setLabel(sprintf('%s <span style="color:#b3b3b3; padding-left:3px">[%%s]</span>', $event->getLabel()));
 }
Ejemplo n.º 5
0
 /**
  * Render a filter setting into html.
  *
  * @param ModelToLabelEvent $event The event.
  *
  * @return void
  */
 public function modelToLabel(ModelToLabelEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_filtersetting' || in_array($event->getModel()->getProperty('type'), $this->getTypes())) {
         return;
     }
     $environment = $event->getEnvironment();
     $model = $event->getModel();
     $event->setLabel($this->getLabelPattern($environment, $model))->setArgs($this->getLabelParameters($environment, $model));
 }
Ejemplo n.º 6
0
 /**
  * Render an attribute or legend.
  *
  * @param ModelToLabelEvent $event The event.
  *
  * @return void
  */
 public function handleModelToLabel(ModelToLabelEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_dcasetting') {
         return;
     }
     $model = $event->getModel();
     switch ($model->getProperty('dcatype')) {
         case 'attribute':
             self::drawAttribute($event);
             break;
         case 'legend':
             self::drawLegend($event);
             break;
         default:
             break;
     }
 }
Ejemplo n.º 7
0
 /**
  * Render the html for the input screen condition.
  *
  * @param ModelToLabelEvent $event The event.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 public function handleModelToLabel(ModelToLabelEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_dcasetting_condition') {
         return;
     }
     $environment = $event->getEnvironment();
     $translator = $environment->getTranslator();
     $model = $event->getModel();
     $metaModels = $this->getMetaModel($environment);
     $attribute = $metaModels->getAttributeById($model->getProperty('attr_id'));
     $type = $model->getProperty('type');
     $parameterValue = is_array($model->getProperty('value')) ? implode(', ', $model->getProperty('value')) : $model->getProperty('value');
     $name = $translator->translate('conditionnames.' . $type, 'tl_metamodel_dcasetting_condition');
     $image = $GLOBALS['METAMODELS']['attributes'][$type]['image'];
     if (!$image || !file_exists(TL_ROOT . '/' . $image)) {
         $image = 'system/modules/metamodels/assets/images/icons/filter_default.png';
     }
     /** @var GenerateHtmlEvent $imageEvent */
     $imageEvent = $event->getEnvironment()->getEventDispatcher()->dispatch(ContaoEvents::IMAGE_GET_HTML, new GenerateHtmlEvent($image));
     $event->setLabel($this->getLabelText($translator, $type))->setArgs(array($imageEvent->getHtml(), $name, $attribute ? $attribute->getName() : '', $parameterValue));
 }
Ejemplo n.º 8
0
 /**
  * Draw the attribute in the backend listing.
  *
  * @param ModelToLabelEvent $event The event.
  *
  * @return void
  */
 public function modelToLabel(ModelToLabelEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_attribute') {
         return;
     }
     $services = $this->getServiceContainer();
     $factory = $services->getAttributeFactory();
     $model = $event->getModel();
     $type = $model->getProperty('type');
     $image = '<img src="' . $factory->getIconForType($type) . '" />';
     $metaModel = $this->getMetaModelByModelPid($model);
     $attribute = $factory->createAttribute($model->getPropertiesAsArray(), $metaModel);
     if (!$attribute) {
         $translator = $event->getEnvironment()->getTranslator();
         $event->setLabel('<div class="field_heading cte_type"><strong>%s</strong> <em>[%s]</em></div>
                 <div class="field_type block">
                     <strong>%s</strong><br />
                 </div>')->setArgs(array($translator->translate('error_unknown_attribute.0', 'tl_metamodel_attribute'), $type, $translator->translate('error_unknown_attribute.1', 'tl_metamodel_attribute', array($type))));
         return;
     }
     $colName = $attribute->getColName();
     $name = $attribute->getName();
     $arrDescription = deserialize($attribute->get('description'));
     if (is_array($arrDescription)) {
         $description = $arrDescription[$attribute->getMetaModel()->getActiveLanguage()];
         if (!$description) {
             $description = $arrDescription[$attribute->getMetaModel()->getFallbackLanguage()];
         }
     } else {
         $description = $attribute->getName();
     }
     $event->setLabel('<div class="field_heading cte_type"><strong>%s</strong> <em>[%s]</em></div>
             <div class="field_type block">
                 %s<strong>%s</strong> - %s
             </div>')->setArgs(array($colName, $type, $image, $name, $description));
 }
Ejemplo n.º 9
0
 /**
  * Render a model in the backend list.
  *
  * @param ModelToLabelEvent $event The event.
  *
  * @return void
  */
 public function modelToLabel(ModelToLabelEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel') {
         return;
     }
     $model = $event->getModel();
     $translator = $event->getEnvironment()->getTranslator();
     $database = $this->getDatabase();
     if (!($model && $database->tableExists($model->getProviderName()))) {
         return;
     }
     $strLabel = vsprintf($event->getLabel(), $event->getArgs());
     $strImage = '';
     if ($model->getProperty('addImage')) {
         $arrSize = deserialize($model->getProperty('size'));
         $imageEvent = new ResizeImageEvent($model->getProperty('singleSRC'), $arrSize[0], $arrSize[1], $arrSize[2]);
         $event->getEnvironment()->getEventDispatcher()->dispatch(ContaoEvents::IMAGE_RESIZE, $event);
         $strImage = sprintf('<div class="image" style="padding-top:3px"><img src="%s" alt="%%1$s" /></div> ', $imageEvent->getImage(), htmlspecialchars($strLabel));
     }
     $objCount = $database->prepare('SELECT count(*) AS itemCount FROM ' . $model->getProperty('tableName'))->execute();
     /** @noinspection PhpUndefinedFieldInspection */
     $count = $objCount->itemCount;
     $itemCount = sprintf('<span style="color:#b3b3b3; padding-left:3px">[%s]</span>', $translator->translatePluralized('itemFormatCount', $count, 'tl_metamodel', array($count)));
     $tableName = '<span style="color:#b3b3b3; padding-left:3px">(' . $model->getProperty('tableName') . ')</span>';
     $event->setArgs(array('<span class="name">' . $strLabel . $tableName . $itemCount . '</span>' . $strImage));
 }
 /**
  * Retrieve the arguments for the callback.
  *
  * @param ModelToLabelEvent $event The event being emitted.
  *
  * @return array
  */
 public function getArgs($event)
 {
     return array($event->getModel()->getPropertiesAsArray(), $event->getLabel(), new DcCompat($event->getEnvironment(), $event->getModel()), $event->getArgs());
 }
Ejemplo n.º 11
0
 /**
  * Draw the render setting.
  *
  * @param ModelToLabelEvent $event The event.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 public function modelToLabel(ModelToLabelEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_rendersetting') {
         return;
     }
     $model = $event->getModel();
     $attribute = $this->getMetaModel($model)->getAttributeById($model->getProperty('attr_id'));
     if ($attribute) {
         $type = $attribute->get('type');
         $image = $GLOBALS['METAMODELS']['attributes'][$type]['image'];
         if (!$image || !file_exists(TL_ROOT . '/' . $image)) {
             $image = 'system/modules/metamodels/assets/images/icons/fields.png';
         }
         $name = $attribute->getName();
         $colName = $attribute->getColName();
     } else {
         $translator = $event->getEnvironment()->getTranslator();
         $image = 'system/modules/metamodels/assets/images/icons/fields.png';
         $name = $translator->translate('error_unknown_id', 'error_unknown_attribute');
         $colName = $translator->translate('error_unknown_column', 'error_unknown_attribute');
         $type = $translator->translate('error_unknown_id', 'tl_metamodel_rendersettings', array($model->getProperty('attr_id')));
     }
     /** @var GenerateHtmlEvent $imageEvent */
     $imageEvent = $event->getEnvironment()->getEventDispatcher()->dispatch(ContaoEvents::IMAGE_GET_HTML, new GenerateHtmlEvent($image));
     $event->setLabel('<div class="field_heading cte_type %s"><strong>%s</strong> <em>[%s]</em></div>
             <div class="field_type block">
                 %s<strong>%s</strong>
             </div>')->setArgs(array($model->getProperty('enabled') ? 'published' : 'unpublished', $colName, $type, $imageEvent->getHtml(), $name));
 }