src/Contao/View/Contao2BackendView/TreePicker.php
public function formatModel(ModelInterface $model, $treeMode = true)
    {
        /** @var ListingConfigInterface $listing */
        $environment  = $this->getEnvironment();
        $definition   = $environment->getDataDefinition();
        $listing      = $definition->getDefinition(Contao2BackendViewDefinitionInterface::NAME)->getListingConfig();
        $properties   = $definition->getPropertiesDefinition();
        $firstSorting = \reset(\array_keys((array) $listing->getDefaultSortingFields()));
        $formatter    = $this->getFormatter($model, $treeMode);

        $arguments = [];
        foreach ($formatter->getPropertyNames() as $propertyName) {
            if ($properties->hasProperty($propertyName)) {
                $arguments[$propertyName] = (string) $model->getProperty($propertyName);
            } else {
                $arguments[$propertyName] = '-';
            }
        }

        $event = new ModelToLabelEvent($environment, $model);
        $event
            ->setArgs($arguments)
            ->setLabel($formatter->getFormat())
            ->setFormatter($formatter);

        $environment->getEventDispatcher()->dispatch($event::NAME, $event);

        $labelList = [];
        $this->prepareLabelWithDisplayedProperties($formatter, $event->getArgs(), $firstSorting, $labelList);
        $this->prepareLabelWithOutDisplayedProperties($formatter, $event->getArgs(), $event->getLabel(), $labelList);

        return $labelList;
    }
public function formatModel(ModelInterface $model, $treeMode = true)
    {
        /** @var ListingConfigInterface $listing */
        $environment  = $this->getEnvironment();
        $definition   = $environment->getDataDefinition();
        $listing      = $definition->getDefinition(Contao2BackendViewDefinitionInterface::NAME)->getListingConfig();
        $properties   = $definition->getPropertiesDefinition();
        $firstSorting = \reset(\array_keys((array) $listing->getDefaultSortingFields()));
        $formatter    = $this->getFormatter($model, $treeMode);

        $arguments = [];
        foreach ($formatter->getPropertyNames() as $propertyName) {
            if ($properties->hasProperty($propertyName)) {
                $arguments[$propertyName] = (string) $model->getProperty($propertyName);
            } else {
                $arguments[$propertyName] = '-';
            }
        }

        $event = new ModelToLabelEvent($environment, $model);
        $event
            ->setArgs($arguments)
            ->setLabel($formatter->getFormat())
            ->setFormatter($formatter);

        $environment->getEventDispatcher()->dispatch($event::NAME, $event);

        $labelList = [];
        $this->prepareLabelWithDisplayedProperties($formatter, $event->getArgs(), $firstSorting, $labelList);
        $this->prepareLabelWithOutDisplayedProperties($formatter, $event->getArgs(), $event->getLabel(), $labelList);

        return $labelList;
    }
public function formatModel ( ModelInterface $ model , $ treeMode = true ) { /** @var ListingConfigInterface $listing */ $ environment = $ this -> getEnvironment ( ) ; $ definition = $ environment -> getDataDefinition ( ) ; $ listing = $ definition -> getDefinition ( Contao2BackendViewDefinitionInterface :: NAME ) -> getListingConfig ( ) ; $ properties = $ definition -> getPropertiesDefinition ( ) ; $ firstSorting = \ reset ( \ array_keys ( ( array ) $ listing -> getDefaultSortingFields ( ) ) ) ; $ formatter = $ this -> getFormatter ( $ model , $ treeMode ) ; $ arguments = [ ] ; foreach ( $ formatter -> getPropertyNames ( ) as $ propertyName ) { if ( $ properties -> hasProperty ( $ propertyName ) ) { $ arguments [ $ propertyName ] = ( string ) $ model -> getProperty ( $ propertyName ) ; } else { $ arguments [ $ propertyName ] = '-' ; } } $ event = new ModelToLabelEvent ( $ environment , $ model ) ; $ event -> setArgs ( $ arguments ) -> setLabel ( $ formatter -> getFormat ( ) ) -> setFormatter ( $ formatter ) ; $ environment -> getEventDispatcher ( ) -> dispatch ( $ event :: NAME , $ event ) ; $ labelList = [ ] ; $ this -> prepareLabelWithDisplayedProperties ( $ formatter , $ event -> getArgs ( ) , $ firstSorting , $ labelList ) ; $ this -> prepareLabelWithOutDisplayedProperties ( $ formatter , $ event -> getArgs ( ) , $ event -> getLabel ( ) , $ labelList ) ; return $ labelList ; }
Format a model accordingly to the current configuration.

Returns either an array when in tree mode or a string in (parented) list mode.

@param ModelInterface $model    The model that shall be formatted.
@param bool           $treeMode Flag if we are running in tree mode or not (optional, default: true).

@return array
Format a model accordingly to the current configuration .