src/Contao/Subscriber/FormatModelLabelSubscriber.php
public function handleFormatModelLabel(FormatModelLabelEvent $event)
    {
        if (!$this->scopeDeterminator->currentScopeIsBackend()) {
            return;
        }

        $environment = $event->getEnvironment();
        $model       = $event->getModel();

        $dataDefinition = $environment->getDataDefinition();
        /** @var Contao2BackendViewDefinitionInterface $viewSection */
        $viewSection   = $dataDefinition->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
        $listing       = $viewSection->getListingConfig();
        $properties    = $dataDefinition->getPropertiesDefinition();
        $formatter     = $listing->getLabelFormatter($model->getProviderName());
        $sorting       = ViewHelpers::getGroupingMode($environment);
        $firstSorting  = $this->getFirstSorting($sorting['sorting']);
        $propertyNames = $formatter->getPropertyNames();

        $modelToLabelEvent = new ModelToLabelEvent($environment, $model);
        $modelToLabelEvent
            ->setArgs($this->prepareLabelArguments($propertyNames, $properties, $environment, $model))
            ->setLabel($formatter->getFormat())
            ->setFormatter($formatter);

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

        // Add columns.
        if ($listing->getShowColumns()) {
            $event->setLabel($this->renderWithColumns($propertyNames, $modelToLabelEvent->getArgs(), $firstSorting));
            return;
        }

        $event->setLabel(
            [
                [
                    'colspan' => null,
                    'class'   => 'tl_file_list',
                    'content' => $this->renderSingleValue(
                        $modelToLabelEvent->getLabel(),
                        $modelToLabelEvent->getArgs(),
                        $formatter->getMaxLength()
                    )
                ]
            ]
        );
    }
public function handleFormatModelLabel(FormatModelLabelEvent $event)
    {
        if (!$this->scopeDeterminator->currentScopeIsBackend()) {
            return;
        }

        $environment = $event->getEnvironment();
        $model       = $event->getModel();

        $dataDefinition = $environment->getDataDefinition();
        /** @var Contao2BackendViewDefinitionInterface $viewSection */
        $viewSection   = $dataDefinition->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
        $listing       = $viewSection->getListingConfig();
        $properties    = $dataDefinition->getPropertiesDefinition();
        $formatter     = $listing->getLabelFormatter($model->getProviderName());
        $sorting       = ViewHelpers::getGroupingMode($environment);
        $firstSorting  = $this->getFirstSorting($sorting['sorting']);
        $propertyNames = $formatter->getPropertyNames();

        $modelToLabelEvent = new ModelToLabelEvent($environment, $model);
        $modelToLabelEvent
            ->setArgs($this->prepareLabelArguments($propertyNames, $properties, $environment, $model))
            ->setLabel($formatter->getFormat())
            ->setFormatter($formatter);

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

        // Add columns.
        if ($listing->getShowColumns()) {
            $event->setLabel($this->renderWithColumns($propertyNames, $modelToLabelEvent->getArgs(), $firstSorting));
            return;
        }

        $event->setLabel(
            [
                [
                    'colspan' => null,
                    'class'   => 'tl_file_list',
                    'content' => $this->renderSingleValue(
                        $modelToLabelEvent->getLabel(),
                        $modelToLabelEvent->getArgs(),
                        $formatter->getMaxLength()
                    )
                ]
            ]
        );
    }
public function handleFormatModelLabel ( FormatModelLabelEvent $ event ) { if ( ! $ this -> scopeDeterminator -> currentScopeIsBackend ( ) ) { return ; } $ environment = $ event -> getEnvironment ( ) ; $ model = $ event -> getModel ( ) ; $ dataDefinition = $ environment -> getDataDefinition ( ) ; /** @var Contao2BackendViewDefinitionInterface $viewSection */ $ viewSection = $ dataDefinition -> getDefinition ( Contao2BackendViewDefinitionInterface :: NAME ) ; $ listing = $ viewSection -> getListingConfig ( ) ; $ properties = $ dataDefinition -> getPropertiesDefinition ( ) ; $ formatter = $ listing -> getLabelFormatter ( $ model -> getProviderName ( ) ) ; $ sorting = ViewHelpers :: getGroupingMode ( $ environment ) ; $ firstSorting = $ this -> getFirstSorting ( $ sorting [ 'sorting' ] ) ; $ propertyNames = $ formatter -> getPropertyNames ( ) ; $ modelToLabelEvent = new ModelToLabelEvent ( $ environment , $ model ) ; $ modelToLabelEvent -> setArgs ( $ this -> prepareLabelArguments ( $ propertyNames , $ properties , $ environment , $ model ) ) -> setLabel ( $ formatter -> getFormat ( ) ) -> setFormatter ( $ formatter ) ; $ environment -> getEventDispatcher ( ) -> dispatch ( ModelToLabelEvent :: NAME , $ modelToLabelEvent ) ; // Add columns. if ( $ listing -> getShowColumns ( ) ) { $ event -> setLabel ( $ this -> renderWithColumns ( $ propertyNames , $ modelToLabelEvent -> getArgs ( ) , $ firstSorting ) ) ; return ; } $ event -> setLabel ( [ [ 'colspan' => null , 'class' => 'tl_file_list' , 'content' => $ this -> renderSingleValue ( $ modelToLabelEvent -> getLabel ( ) , $ modelToLabelEvent -> getArgs ( ) , $ formatter -> getMaxLength ( ) ) ] ] ) ; }
Default handler for formatting a model.

@param FormatModelLabelEvent $event The event.

@return void
Default handler for formatting a model .