/** * Retrieve the formatter for the given model. * * @param ModelInterface $model The model for which the formatter shall be retrieved. * @param bool $treeMode Flag if we are running in tree mode or not. * * @return ModelFormatterConfigInterface */ protected function getFormatter(ModelInterface $model, $treeMode) { /** @var ListingConfigInterface $listing */ $definition = $this->getEnvironment()->getDataDefinition(); $listing = $definition->getDefinition(Contao2BackendViewDefinitionInterface::NAME)->getListingConfig(); if ($listing->hasLabelFormatter($model->getProviderName())) { return $listing->getLabelFormatter($model->getProviderName()); } // If not in tree mode and custom label has been defined, use it. if (!$treeMode && $this->itemLabel) { $label = $this->itemLabel; $formatter = new DefaultModelFormatterConfig(); $formatter->setPropertyNames($label['fields']); $formatter->setFormat($label['format']); $formatter->setMaxLength($label['maxCharacters']); return $formatter; } // If no label has been defined, use some default. $properties = array(); foreach ($definition->getPropertiesDefinition()->getProperties() as $property) { if ($property->getWidgetType() == 'text') { $properties[] = $property->getName(); } } $formatter = new DefaultModelFormatterConfig(); $formatter->setPropertyNames($properties); $formatter->setFormat(str_repeat('%s ', count($properties))); return $formatter; }
/** * Parse the sorting part of listing configuration. * * @param ContainerInterface $container The container where the data shall be stored. * * @param ListingConfigInterface $listing The listing configuration definition to populate. * * @param array $listDca The DCA part containing the information to use. * * @return void */ protected function parseListLabel(ContainerInterface $container, ListingConfigInterface $listing, array $listDca) { $labelDca = isset($listDca['label']) ? $listDca['label'] : array(); $formatter = new DefaultModelFormatterConfig(); $configured = false; if (isset($labelDca['fields'])) { $formatter->setPropertyNames($labelDca['fields']); $configured = true; } if (isset($labelDca['format'])) { $formatter->setFormat($labelDca['format']); $configured = true; } if (isset($labelDca['maxCharacters'])) { $formatter->setMaxLength($labelDca['maxCharacters']); $configured = true; } if ($configured) { $listing->setLabelFormatter($container->getBasicDefinition()->getDataProvider(), $formatter); } if (isset($labelDca['showColumns'])) { $listing->setShowColumns($labelDca['showColumns']); } }
/** * Parse the sorting part of listing configuration. * * @param ListingConfigInterface $listing The listing configuration to be populated. * * @return void */ protected function parseListLabel(ListingConfigInterface $listing) { if (($formats = $this->getFromDca('dca_config/child_list')) === null) { return; } foreach ($formats as $providerName => $format) { $formatter = new DefaultModelFormatterConfig(); $configured = false; if (isset($format['fields'])) { $formatter->setPropertyNames($format['fields']); $configured = true; } if (isset($format['format'])) { $formatter->setFormat($format['format']); $configured = true; } if (isset($format['maxCharacters'])) { $formatter->setMaxLength($format['maxCharacters']); $configured = true; } if ($configured) { $listing->setLabelFormatter($providerName, $formatter); } } }