/** * Default handler for formatting a model. * * @param FormatModelLabelEvent $event The event. * * @return void */ public function handleFormatModelLabel(FormatModelLabelEvent $event) { $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); $sortingDefinition = $sorting['sorting']; $firstSorting = ''; if ($sortingDefinition) { /** @var GroupAndSortingDefinitionInterface $sortingDefinition */ foreach ($sortingDefinition as $information) { /** @var GroupAndSortingInformationInterface $information */ if ($information->getProperty()) { $firstSorting = reset($sorting); break; } } } $args = array(); foreach ($formatter->getPropertyNames() as $propertyName) { if ($properties->hasProperty($propertyName)) { $property = $properties->getProperty($propertyName); $args[$propertyName] = (string) ViewHelpers::getReadableFieldValue($environment, $property, $model); } else { $args[$propertyName] = '-'; } } $modelToLabelEvent = new ModelToLabelEvent($environment, $model); $modelToLabelEvent->setArgs($args)->setLabel($formatter->getFormat())->setFormatter($formatter); $environment->getEventDispatcher()->dispatch(ModelToLabelEvent::NAME, $modelToLabelEvent); $label = array(); // Add columns. if ($listing->getShowColumns()) { $fields = $formatter->getPropertyNames(); $args = $modelToLabelEvent->getArgs(); if (!is_array($args)) { $label[] = array('colspan' => count($fields), 'class' => 'tl_file_list col_1', 'content' => $args); } else { foreach ($fields as $j => $propertyName) { $label[] = array('colspan' => 1, 'class' => 'tl_file_list col_' . $j . ($propertyName == $firstSorting ? ' ordered_by' : ''), 'content' => $args[$propertyName] != '' ? $args[$propertyName] : '-'); } } } else { if (!is_array($modelToLabelEvent->getArgs())) { $string = $modelToLabelEvent->getArgs(); } else { $string = vsprintf($modelToLabelEvent->getLabel(), $modelToLabelEvent->getArgs()); } if ($formatter->getMaxLength() !== null && strlen($string) > $formatter->getMaxLength()) { $string = substr($string, 0, $formatter->getMaxLength()); } $label[] = array('colspan' => null, 'class' => 'tl_file_list', 'content' => $string); } $event->setLabel($label); }
/** * Handle the action. * * @return void */ public function process() { $event = $this->getEvent(); if ($event->getAction()->getName() !== 'paste') { return; } $environment = $this->getEnvironment(); $input = $environment->getInputProvider(); $clipboard = $environment->getClipboard(); $definition = $environment->getDataDefinition()->getBasicDefinition(); // Tree mode needs special handling. if ($this->needTreeModeShowAll($definition, $input)) { $this->callAction('showAll'); return; } // Check if it is a simple create-paste of a single model, if so, redirect to edit view. if ($this->isSimpleCreatePaste($clipboard, $environment->getDataDefinition()->getBasicDefinition()->getDataProvider())) { $this->callAction('create'); return; } $controller = $environment->getController(); $after = $this->modelIdFromParameter($input, 'after'); $into = $this->modelIdFromParameter($input, 'into'); $parentModelId = $this->modelIdFromParameter($input, 'pid'); $items = array(); $controller->applyClipboardActions(null, $after, $into, $parentModelId, null, $items); foreach ($items as $item) { $clipboard->remove($item); } $clipboard->saveTo($environment); ViewHelpers::redirectHome($environment); }
/** * Handle the action. * * @return void */ public function process() { $environment = $this->getEnvironment(); $inputProvider = $environment->getInputProvider(); $event = $this->getEvent(); $action = $event->getAction(); // Only handle if we do not have a manual sorting or we know where to insert. // Manual sorting is handled by clipboard. if ($action->getName() !== 'create' || ViewHelpers::getManualSortingProperty($environment) && !$inputProvider->hasParameter('after') && !$inputProvider->hasParameter('into')) { return; } $definition = $environment->getDataDefinition(); $dataProvider = $environment->getDataProvider(); $propertyDefinition = $definition->getPropertiesDefinition(); $properties = $propertyDefinition->getProperties(); $model = $dataProvider->getEmptyModel(); $clone = $dataProvider->getEmptyModel(); // If some of the fields have a default value, set it. foreach ($properties as $property) { $propName = $property->getName(); if ($property->getDefaultValue() !== null) { $model->setProperty($propName, $property->getDefaultValue()); $clone->setProperty($propName, $property->getDefaultValue()); } } $view = $environment->getView(); if (!$view instanceof BaseView) { return; } $editMask = new EditMask($view, $model, $clone, null, null, $view->breadcrumb()); $event->setResponse($editMask->execute()); }
/** * Handle the action. * * @return void */ public function process() { $environment = $this->getEnvironment(); $inputProvider = $environment->getInputProvider(); $event = $this->getEvent(); $action = $event->getAction(); // Only handle if we does not have a manual sorting or we know where to insert. // Manual sorting is handled by clipboard. if ($action->getName() !== 'create' || ViewHelpers::getManualSortingProperty($environment) && !$inputProvider->hasParameter('after')) { return; } $dataProvider = $environment->getDataProvider(); $model = $dataProvider->getEmptyModel(); $clone = $dataProvider->getEmptyModel(); $view = $environment->getView(); if (!$view instanceof BaseView) { return; } $editMask = new EditMask($view, $model, $clone, null, null, $view->breadcrumb()); $event->setResponse($editMask->execute()); }
/** * Handle "old" add to clipboard actions. * * @param ActionEvent $event The action event. * * @return void */ private function addToClipboard(ActionEvent $event) { $actionName = $event->getAction()->getName(); $environment = $event->getEnvironment(); $input = $environment->getInputProvider(); $clipboard = $environment->getClipboard(); if ('create' === $actionName) { $modelId = IdSerializer::fromValues($environment->getDataDefinition()->getBasicDefinition()->getDataProvider(), null); } else { $modelIdRaw = $input->getParameter('source'); $modelId = IdSerializer::fromSerialized($modelIdRaw); } $parentIdRaw = $input->getParameter('pid'); if ($parentIdRaw) { $parentId = IdSerializer::fromSerialized($parentIdRaw); } else { $parentId = null; } // Push some entry into clipboard. if ($modelId) { $clipboardActionName = $this->translateActionName($actionName); if ($clipboardActionName) { // Remove other create items, there can only be one create item in the clipboard or many others if (Item::CREATE === $clipboardActionName) { $clipboard->clear(); } else { $filter = new Filter(); $filter->andActionIs(ItemInterface::CREATE); $items = $clipboard->fetch($filter); foreach ($items as $item) { $clipboard->remove($item); } } // Only push item to clipboard if manual sorting is used. if (Item::COPY === $clipboardActionName && !ViewHelpers::getManualSortingProperty($environment)) { return; } // create the new item $item = new Item($clipboardActionName, $parentId, $modelId); // Let the clipboard save it's values persistent. // TODO remove clear and allow adding multiple items $clipboard->clear()->push($item)->saveTo($environment); ViewHelpers::redirectHome($environment); } } }
/** * Create a new instance. * * @param EnvironmentInterface $environment The environment. */ public function __construct(EnvironmentInterface $environment) { $this->environment = $environment; $this->translator = $environment->getTranslator(); $this->eventDispatcher = $environment->getEventDispatcher(); $this->clipboardItems = $this->calculateClipboardItems(); $dataDefinition = $environment->getDataDefinition(); $basicDefinition = $dataDefinition->getBasicDefinition(); $this->isHierarchical = $basicDefinition::MODE_HIERARCHICAL === $basicDefinition->getMode(); $this->commands = $dataDefinition->getDefinition(Contao2BackendViewDefinitionInterface::NAME)->getModelCommands(); $controller = $environment->getController(); $this->clipboardModels = $controller->getModelsFromClipboardItems($this->clipboardItems); $this->circularModelIds = array(); // We must only check for CUT operation here as pasting copy'ed parents is allowed. $cutItems = array_filter($this->clipboardItems, function ($item) { /** @var ItemInterface $item */ return $item->getAction() === $item::CUT; }); $cutModels = $controller->getModelsFromClipboardItems($cutItems); foreach ($cutModels as $model) { $providerName = $model->getProviderName(); foreach ($controller->assembleAllChildrenFrom($model) as $subModel) { $this->circularModelIds[] = ModelId::fromValues($providerName, $subModel)->getSerialized(); } } if (null !== ViewHelpers::getManualSortingProperty($environment)) { $this->hasPasteButtons = !empty($this->clipboardItems); $this->hasPasteNewButton = empty($this->clipboardItems) && !$this->isHierarchical; } else { $this->hasPasteButtons = false; $this->hasPasteNewButton = false; } }
/** * Retrieve the manual sorting property if any is defined. * * @return string|null */ protected function getManualSortingProperty() { return ViewHelpers::getManualSortingProperty($this->getEnvironment()); }
/** * Check the get parameters if there is any node toggling. * * CAUTION: If there has been any action, the browser will get redirected and the script therefore exited. * * @return void */ private function handleNodeStateChanges() { $input = $this->getEnvironment()->getInputProvider(); if (($modelId = $input->getParameter('ptg')) && ($providerName = $input->getParameter('provider'))) { $states = $this->getTreeNodeStates(); // Check if the open/close all has been triggered or just a model. if ($modelId == 'all') { if ($states->isAllOpen()) { $states->resetAll(); } $states->setAllOpen($states->isAllOpen()); } else { $this->toggleModel($providerName, $modelId); } ViewHelpers::redirectHome($this->environment); } }
/** * Apply sorting and persist all models. * * @param array $actions The actions collection. * @param ModelIdInterface $after The previous model id. * @param ModelIdInterface $into The hierarchical parent model id. * @param ModelIdInterface $parentModelId The parent model id. * @param array $items Write-back clipboard items. * * @return DefaultCollection|ModelInterface[] * * @throws DcGeneralRuntimeException When the parameters for the pasting destination are invalid. */ private function sortAndPersistModels(array $actions, ModelIdInterface $after = null, ModelIdInterface $into = null, ModelIdInterface $parentModelId = null, array &$items = array()) { $environment = $this->getEnvironment(); $dataDefinition = $environment->getDataDefinition(); $manualSorting = ViewHelpers::getManualSortingProperty($environment); /** @var DefaultCollection|ModelInterface[] $models */ $models = new DefaultCollection(); foreach ($actions as $action) { $models->push($action['model']); $items[] = $action['item']; } // Trigger for each model the pre persist event. foreach ($models as $model) { $event = new PrePasteModelEvent($environment, $model); $environment->getEventDispatcher()->dispatch($event::NAME, $event); } if ($after && $after->getId()) { $dataProvider = $environment->getDataProvider($after->getDataProviderName()); $previous = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($after->getId())); $this->pasteAfter($previous, $models, $manualSorting); } elseif ($into && $into->getId()) { $dataProvider = $environment->getDataProvider($into->getDataProviderName()); $parent = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($into->getId())); $this->pasteInto($parent, $models, $manualSorting); } elseif ($after && $after->getId() == '0' || $into && $into->getId() == '0') { if ($dataDefinition->getBasicDefinition()->getMode() === BasicDefinitionInterface::MODE_HIERARCHICAL) { foreach ($models as $model) { // Paste top means root in hierarchical mode! $this->setRootModel($model); } } $this->pasteTop($models, $manualSorting, $parentModelId); } elseif ($parentModelId) { if ($manualSorting) { $this->pasteTop($models, $manualSorting, $parentModelId); } else { $dataProvider = $environment->getDataProvider(); $dataProvider->saveEach($models); } } else { throw new DcGeneralRuntimeException('Invalid parameters.'); } // Trigger for each model the past persist event. foreach ($models as $model) { $event = new PostPasteModelEvent($environment, $model); $environment->getEventDispatcher()->dispatch($event::NAME, $event); } return $models; }
/** * Is adding to the clipboard allowed. * * @param EnvironmentInterface $environment The environment. * * @return bool */ protected function isAddingAllowed(EnvironmentInterface $environment) { $inputProvider = $environment->getInputProvider(); // No manual sorting property defined, no need to add it to the clipboard. // Or we already have an after or into attribute, a handler can pick it up. return !ViewHelpers::getManualSortingProperty($environment) || $inputProvider->hasParameter('after') || $inputProvider->hasParameter('into'); }
/** * Convert a model to it's labels and human readable values. * * @param ModelInterface $model The model to display. * * @param EnvironmentInterface $environment The environment. * * @return array * * @throws DcGeneralRuntimeException When a property could not be retrieved. */ protected function convertModel($model, $environment) { $definition = $environment->getDataDefinition(); $properties = $definition->getPropertiesDefinition(); $palette = $definition->getPalettesDefinition()->findPalette($model); $values = array(); $labels = array(); // Show only allowed fields. foreach ($palette->getVisibleProperties($model) as $paletteProperty) { $property = $properties->getProperty($paletteProperty->getName()); if (!$property) { throw new DcGeneralRuntimeException('Unable to retrieve property ' . $paletteProperty->getName()); } // Make it human readable. $values[$paletteProperty->getName()] = ViewHelpers::getReadableFieldValue($this->getEnvironment(), $property, $model); $labels[$paletteProperty->getName()] = $this->getPropertyLabel($property); } return array('labels' => $labels, 'values' => $values); }
/** * Compile buttons from the table configuration array and return them as HTML. * * @param ModelInterface $model The model for which the buttons shall be generated for. * @param ModelInterface $previous The previous model in the collection. * @param ModelInterface $next The next model in the collection. * * @return string */ protected function generateButtons(ModelInterface $model, ModelInterface $previous = null, ModelInterface $next = null) { $environment = $this->getEnvironment(); $dataDefinition = $environment->getDataDefinition(); $basicDefinition = $dataDefinition->getBasicDefinition(); $commands = $this->getViewSection()->getModelCommands(); $clipboard = $environment->getClipboard(); $dispatcher = $environment->getEventDispatcher(); $filter = new Filter(); $filter->andModelIsFromProvider($basicDefinition->getDataProvider()); if ($parentDataProviderName = $basicDefinition->getParentDataProvider()) { $filter->andParentIsFromProvider($parentDataProviderName); } else { $filter->andHasNoParent(); } if ($clipboard->isNotEmpty($filter)) { $circularIds = $clipboard->getCircularIds(); $isCircular = in_array(ModelId::fromModel($model)->getSerialized(), $circularIds); } else { $circularIds = array(); $isCircular = false; } $arrButtons = array(); foreach ($commands->getCommands() as $command) { $arrButtons[$command->getName()] = $this->buildCommand($command, $model, $isCircular, $circularIds, $previous, $next); } if (ViewHelpers::getManualSortingProperty($this->environment)) { $clipboardIsEmpty = $clipboard->isEmpty($filter); if ($clipboardIsEmpty && BasicDefinitionInterface::MODE_HIERARCHICAL !== $basicDefinition->getMode()) { /** @var AddToUrlEvent $urlEvent */ $urlEvent = $dispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, new AddToUrlEvent('act=create&after=' . ModelId::fromModel($model)->getSerialized())); /** @var GenerateHtmlEvent $imageEvent */ $imageEvent = $dispatcher->dispatch(ContaoEvents::IMAGE_GET_HTML, new GenerateHtmlEvent('new.gif', $this->translate('pastenew.0', $this->getDataDefinition()->getName()))); $arrButtons['pasteNew'] = sprintf('<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a>', $urlEvent->getUrl(), specialchars($this->translate('pastenew.1', $this->getDataDefinition()->getName())), $imageEvent->getHtml()); } // Add paste into/after icons. if (!$clipboardIsEmpty) { if ($clipboard->isCreate()) { // Add ext. information. $add2UrlAfter = sprintf('act=create&after=%s&', ModelId::fromModel($model)->getSerialized()); $add2UrlInto = sprintf('act=create&into=%s&', ModelId::fromModel($model)->getSerialized()); } else { // Add ext. information. $add2UrlAfter = sprintf('act=paste&after=%s&', ModelId::fromModel($model)->getSerialized()); $add2UrlInto = sprintf('act=paste&into=%s&', ModelId::fromModel($model)->getSerialized()); } /** @var AddToUrlEvent $urlAfter */ $urlAfter = $dispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, new AddToUrlEvent($add2UrlAfter)); /** @var AddToUrlEvent $urlInto */ $urlInto = $dispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, new AddToUrlEvent($add2UrlInto)); $models = $this->environment->getController()->getModelsFromClipboard($parentDataProviderName ? IdSerializer::fromValues($parentDataProviderName, null) : null); $buttonEvent = new GetPasteButtonEvent($this->getEnvironment()); $buttonEvent->setModel($model)->setCircularReference($isCircular)->setPrevious($previous)->setNext($next)->setHrefAfter($urlAfter->getUrl())->setHrefInto($urlInto->getUrl())->setPasteAfterDisabled($clipboard->isCut() && $isCircular)->setPasteIntoDisabled($clipboard->isCut() && $isCircular)->setContainedModels($models); $this->getEnvironment()->getEventDispatcher()->dispatch(GetPasteButtonEvent::NAME, $buttonEvent); $arrButtons['pasteafter'] = $this->renderPasteAfterButton($buttonEvent); if ($this->getDataDefinition()->getBasicDefinition()->getMode() == BasicDefinitionInterface::MODE_HIERARCHICAL) { $arrButtons['pasteinto'] = $this->renderPasteIntoButton($buttonEvent); } } } return implode(' ', $arrButtons); }
/** * Format the group header by the grouping mode. * * @param mixed $value The given value. * * @param int $groupingMode The grouping mode. * * @param int $groupingLength The grouping length. * * @param EnvironmentInterface $environment The environment. * * @param PropertyInterface $property The current property definition. * * @param ModelInterface $model The current data model. * * @return string */ private function formatByGroupingMode($value, $groupingMode, $groupingLength, $environment, $property, $model) { $dispatcher = $environment->getEventDispatcher(); switch ($groupingMode) { case GroupAndSortingInformationInterface::GROUP_CHAR: $value = ViewHelpers::getReadableFieldValue($environment, $property, $model); return $value != '' ? ucfirst(utf8_substr($value, 0, $groupingLength ?: null)) : '-'; case GroupAndSortingInformationInterface::GROUP_DAY: $value = $this->getTimestamp($value); $event = new ParseDateEvent($value, \Config::get('dateFormat')); $dispatcher->dispatch(ContaoEvents::DATE_PARSE, $event); return $value != '' ? $event->getResult() : '-'; case GroupAndSortingInformationInterface::GROUP_MONTH: $value = $this->getTimestamp($value); $event = new ParseDateEvent($value, 'F Y'); $dispatcher->dispatch(ContaoEvents::DATE_PARSE, $event); return $event->getResult(); case GroupAndSortingInformationInterface::GROUP_YEAR: if ($value instanceof \DateTime) { $value = $value->getTimestamp(); } return $value != '' ? date('Y', $value) : '-'; default: return ViewHelpers::getReadableFieldValue($environment, $property, $model); } }
/** * {@inheritdoc} */ public function process() { if ($this->getEvent()->getAction()->getName() !== 'delete') { return; } $environment = $this->getEnvironment(); $modelId = ModelId::fromSerialized($environment->getInputProvider()->getParameter('id')); // Guard that we are in the preloaded environment. Otherwise checking the data definition could belong to // another model. $this->guardValidEnvironment($modelId); // Only edit mode is supported. Trigger an edit action. if ($this->isEditOnlyResponse()) { return; } // We want a redirect here if not deletable. $this->guardIsDeletable($modelId, true); $this->delete($modelId); ViewHelpers::redirectHome($this->environment); }
/** * {@inheritdoc} */ public function process() { $event = $this->getEvent(); if ($event->getAction()->getName() !== 'copy') { return; } $environment = $this->getEnvironment(); $modelId = ModelId::fromSerialized($environment->getInputProvider()->getParameter('source')); $this->guardValidEnvironment($modelId); // We want a redirect here if not creatable. $this->guardIsCreatable($modelId, true); if ($this->isEditOnlyResponse()) { return; } // Manual sorting mode. The ClipboardController should pick it up. $manualSortingProperty = ViewHelpers::getManualSortingProperty($environment); if ($manualSortingProperty && $this->environment->getDataProvider()->fieldExists($manualSortingProperty)) { return; } $copiedModel = $this->copy($modelId); $this->redirect($environment, ModelId::fromModel($copiedModel)); }
/** * Handle the delete all action. * * @param ModelIdInterface[] $modelIds The list of model ids. * * @return void */ protected function handleCopyAllAction($modelIds) { if (ViewHelpers::getManualSortingProperty($this->getEnvironment())) { $clipboard = $this->getEnvironment()->getClipboard(); $parentId = $this->getParentId(); foreach ($modelIds as $modelId) { $item = new Item(Item::COPY, $parentId, $modelId); $clipboard->push($item); } $clipboard->saveTo($this->getEnvironment()); } else { $handler = new CopyHandler(); $handler->setEnvironment($this->getEnvironment()); foreach ($modelIds as $modelId) { $handler->copy($modelId); } } ViewHelpers::redirectHome($this->getEnvironment()); }
/** * Handle "old" add to clipboard actions. * * @param ActionEvent $event The action event. * * @return void */ private function addToClipboard(ActionEvent $event) { $actionName = $event->getAction()->getName(); $environment = $event->getEnvironment(); $input = $environment->getInputProvider(); $clipboard = $environment->getClipboard(); $parentIdRaw = $input->getParameter('pid'); if ($parentIdRaw) { $parentId = ModelId::fromSerialized($parentIdRaw); } else { $parentId = null; } $clipboardActionName = $this->translateActionName($actionName); if (!$clipboardActionName) { return; } if ('create' === $actionName) { $inputProvider = $environment->getInputProvider(); // No manual sorting property defined, no need to add it to the clipboard. // Or we already have an after attribute, a handler can pick it up. if (!ViewHelpers::getManualSortingProperty($environment) || $inputProvider->hasParameter('after')) { return; } $providerName = $environment->getDataDefinition()->getBasicDefinition()->getDataProvider(); $item = new UnsavedItem($clipboardActionName, $parentId, $providerName); // Remove other create items, there can only be one create item in the clipboard or many others $clipboard->clear(); } else { $modelIdRaw = $input->getParameter('source'); $modelId = ModelId::fromSerialized($modelIdRaw); $filter = new Filter(); $filter->andActionIs(ItemInterface::CREATE); $items = $clipboard->fetch($filter); foreach ($items as $item) { $clipboard->remove($item); } // Only push item to clipboard if manual sorting is used. if (Item::COPY === $clipboardActionName && !ViewHelpers::getManualSortingProperty($environment)) { return; } // create the new item $item = new Item($clipboardActionName, $parentId, $modelId); } // Let the clipboard save it's values persistent. $clipboard->clear()->push($item)->saveTo($environment); ViewHelpers::redirectHome($environment); }
/** * Generate list view from current collection. * * @param CollectionInterface $collection The collection containing the models. * * @return string */ protected function viewList($collection) { $environment = $this->getEnvironment(); $definition = $environment->getDataDefinition(); $groupingInformation = ViewHelpers::getGroupingMode($this->environment); // Set label. $this->setListViewLabel($collection, $groupingInformation); // Generate buttons - only if not in select mode! if (!$this->isSelectModeActive()) { $buttonRenderer = new ButtonRenderer($this->environment); $buttonRenderer->renderButtonsForCollection($collection); } // Add template. if (isset($groupingInformation['mode']) && $groupingInformation['mode'] != GroupAndSortingInformationInterface::GROUP_NONE) { $objTemplate = $this->getTemplate('dcbe_general_grouping'); } elseif (isset($groupingInformation['property']) && $groupingInformation['property'] != '') { $objTemplate = $this->getTemplate('dcbe_general_listView_sorting'); } else { $objTemplate = $this->getTemplate('dcbe_general_listView'); } $this->addToTemplate('tableName', strlen($definition->getName()) ? $definition->getName() : 'none', $objTemplate)->addToTemplate('collection', $collection, $objTemplate)->addToTemplate('select', $this->getEnvironment()->getInputProvider()->getParameter('act'), $objTemplate)->addToTemplate('action', ampersand(\Environment::get('request'), true), $objTemplate)->addToTemplate('mode', $groupingInformation ? $groupingInformation['mode'] : null, $objTemplate)->addToTemplate('tableHead', $this->getTableHead(), $objTemplate)->addToTemplate('pdp', '', $objTemplate)->addToTemplate('cdp', $definition->getName(), $objTemplate)->addToTemplate('selectButtons', $this->getSelectButtons(), $objTemplate)->addToTemplate('sortable', (bool) ViewHelpers::getManualSortingProperty($this->environment), $objTemplate)->addToTemplate('showColumns', $this->getViewSection()->getListingConfig()->getShowColumns(), $objTemplate); // Add breadcrumb, if we have one. $strBreadcrumb = $this->breadcrumb(); if ($strBreadcrumb != null) { $this->addToTemplate('breadcrumb', $strBreadcrumb, $objTemplate); } return $objTemplate->parse(); }
/** * Show parent view mode 4. * * @param CollectionInterface $collection The collection containing the models. * * @param ModelInterface $parentModel The parent model. * * @return string HTML output */ protected function viewParent($collection, $parentModel) { $definition = $this->getEnvironment()->getDataDefinition(); $parentProvider = $definition->getBasicDefinition()->getParentDataProvider(); $groupingInformation = ViewHelpers::getGroupingMode($this->environment); $dispatcher = $this->getEnvironment()->getEventDispatcher(); // Skip if we have no parent or parent collection. if (!$parentModel) { $dispatcher->dispatch(ContaoEvents::SYSTEM_LOG, new LogEvent(sprintf('The view for %s has either a empty parent data provider or collection.', $parentProvider), __CLASS__ . '::' . __FUNCTION__ . '()', TL_ERROR)); $dispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, new RedirectEvent('contao/main.php?act=error')); } // Add template. if ($groupingInformation && $groupingInformation['mode'] != GroupAndSortingInformationInterface::GROUP_NONE) { $objTemplate = $this->getTemplate('dcbe_general_grouping'); } else { $objTemplate = $this->getTemplate('dcbe_general_parentView'); } $this->addToTemplate('tableName', strlen($definition->getName()) ? $definition->getName() : 'none', $objTemplate)->addToTemplate('collection', $collection, $objTemplate)->addToTemplate('select', $this->isSelectModeActive(), $objTemplate)->addToTemplate('action', ampersand(\Environment::get('request'), true), $objTemplate)->addToTemplate('header', $this->renderFormattedHeaderFields($parentModel), $objTemplate)->addToTemplate('mode', $groupingInformation ? $groupingInformation['mode'] : null, $objTemplate)->addToTemplate('pdp', (string) $parentProvider, $objTemplate)->addToTemplate('cdp', $definition->getName(), $objTemplate)->addToTemplate('selectButtons', $this->getSelectButtons(), $objTemplate)->addToTemplate('headerButtons', $this->getHeaderButtons($parentModel), $objTemplate)->addToTemplate('sortable', (bool) ViewHelpers::getManualSortingProperty($this->environment), $objTemplate)->addToTemplate('showColumns', $this->getViewSection()->getListingConfig()->getShowColumns(), $objTemplate); $this->renderEntries($collection, $groupingInformation); // Add breadcrumb, if we have one. $strBreadcrumb = $this->breadcrumb(); if ($strBreadcrumb != null) { $this->addToTemplate('breadcrumb', $strBreadcrumb, $objTemplate); } return $objTemplate->parse(); }
/** * Initialize the panels for known actions so that they always know their state. * * @param ActionEvent $event The event. * * @return void */ public function initializePanels(ActionEvent $event) { if (!in_array($event->getAction()->getName(), array('copy', 'create', 'paste', 'delete', 'move', 'undo', 'edit', 'toggle', 'showAll', 'show'))) { return; } $environment = $event->getEnvironment(); $definition = $environment->getDataDefinition(); $view = $environment->getView(); if (!$definition->hasDefinition(Contao2BackendViewDefinitionInterface::NAME) || !$view instanceof BaseView || !$view->getPanel()) { return; } /** @var Contao2BackendViewDefinitionInterface $backendDefinition */ $backendDefinition = $definition->getDefinition(Contao2BackendViewDefinitionInterface::NAME); $listingConfig = $backendDefinition->getListingConfig(); $dataConfig = $environment->getBaseConfigRegistry()->getBaseConfig(); $panel = $view->getPanel(); ViewHelpers::initializeSorting($panel, $dataConfig, $listingConfig); }
/** * Generate list view from current collection. * * @param CollectionInterface $collection The collection containing the models. * * @return string */ protected function viewList($collection) { $environment = $this->getEnvironment(); $definition = $environment->getDataDefinition(); $groupingInformation = ViewHelpers::getGroupingMode($this->environment); // Set label. $this->setListViewLabel($collection, $groupingInformation); // Generate buttons. foreach ($collection as $i => $objModel) { // Regular buttons - only if not in select mode! if (!$this->isSelectModeActive()) { $previous = $collection->get($i - 1) !== null ? $collection->get($i - 1) : null; $next = $collection->get($i + 1) !== null ? $collection->get($i + 1) : null; /** @var ModelInterface $objModel */ $objModel->setMeta($objModel::OPERATION_BUTTONS, $this->generateButtons($objModel, $previous, $next)); } } // Add template. if (isset($groupingInformation['mode']) && $groupingInformation['mode'] != GroupAndSortingInformationInterface::GROUP_NONE) { $objTemplate = $this->getTemplate('dcbe_general_grouping'); } elseif (isset($groupingInformation['property']) && $groupingInformation['property'] != '') { $objTemplate = $this->getTemplate('dcbe_general_listView_sorting'); } else { $objTemplate = $this->getTemplate('dcbe_general_listView'); } $this->addToTemplate('tableName', strlen($definition->getName()) ? $definition->getName() : 'none', $objTemplate)->addToTemplate('collection', $collection, $objTemplate)->addToTemplate('select', $this->getEnvironment()->getInputProvider()->getParameter('act'), $objTemplate)->addToTemplate('action', ampersand(\Environment::get('request'), true), $objTemplate)->addToTemplate('mode', $groupingInformation ? $groupingInformation['mode'] : null, $objTemplate)->addToTemplate('tableHead', $this->getTableHead(), $objTemplate)->addToTemplate('pdp', '', $objTemplate)->addToTemplate('cdp', $definition->getName(), $objTemplate)->addToTemplate('selectButtons', $this->getSelectButtons(), $objTemplate)->addToTemplate('sortable', (bool) ViewHelpers::getManualSortingProperty($this->environment), $objTemplate)->addToTemplate('showColumns', $this->getViewSection()->getListingConfig()->getShowColumns(), $objTemplate); // Add breadcrumb, if we have one. $strBreadcrumb = $this->breadcrumb(); if ($strBreadcrumb != null) { $this->addToTemplate('breadcrumb', $strBreadcrumb, $objTemplate); } return $objTemplate->parse(); }