src/Contao/View/Contao2BackendView/TreePicker.php
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     = (array) $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 = [];
        foreach ($definition->getPropertiesDefinition()->getProperties() as $property) {
            if ('text' === $property->getWidgetType()) {
                $properties[] = $property->getName();
            }
        }

        return (new DefaultModelFormatterConfig())
            ->setPropertyNames($properties)
            ->setFormat(\str_repeat('%s ', \count($properties)));
    }
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     = (array) $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 = [];
        foreach ($definition->getPropertiesDefinition()->getProperties() as $property) {
            if ('text' === $property->getWidgetType()) {
                $properties[] = $property->getName();
            }
        }

        return (new DefaultModelFormatterConfig())
            ->setPropertyNames($properties)
            ->setFormat(\str_repeat('%s ', \count($properties)));
    }
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 = ( array ) $ 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 = [ ] ; foreach ( $ definition -> getPropertiesDefinition ( ) -> getProperties ( ) as $ property ) { if ( 'text' === $ property -> getWidgetType ( ) ) { $ properties [ ] = $ property -> getName ( ) ; } } return ( new DefaultModelFormatterConfig ( ) ) -> setPropertyNames ( $ properties ) -> setFormat ( \ str_repeat ( '%s ' , \ count ( $ properties ) ) ) ; }
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
Retrieve the formatter for the given model .