예제 #1
0
 /**
  * Create a new factory with basic settings from the environment.
  *
  * This factory can be used to create a new Container, Environment, DcGeneral with the same base settings as the
  * given environment.
  *
  * @param EnvironmentInterface $environment The environment to use as base.
  *
  * @return DcGeneralFactory
  */
 public static function deriveEmptyFromEnvironment(EnvironmentInterface $environment)
 {
     $factory = new DcGeneralFactory();
     $factory->setEventDispatcher($environment->getEventDispatcher());
     $factory->setEventDispatcher($environment->getEventDispatcher());
     $factory->setTranslator($environment->getTranslator());
     $factory->setEnvironmentClassName(get_class($environment));
     $factory->setContainerClassName(get_class($environment->getDataDefinition()));
     return $factory;
 }
예제 #2
0
 /**
  * {@inheritDoc}
  */
 public function setEnvironment(EnvironmentInterface $environment)
 {
     if ($this->environment) {
         $this->environment->getEventDispatcher()->removeSubscriber($this);
     }
     $this->environment = $environment;
     $this->environment->getEventDispatcher()->addSubscriber($this);
 }
 /**
  * Append wizard icons.
  *
  * @param PropertyInterface    $propInfo    The property for which the wizards shall be generated.
  *
  * @param EnvironmentInterface $environment The environment.
  *
  * @return string
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 public static function getWizard($propInfo, EnvironmentInterface $environment)
 {
     $wizard = '';
     $dispatcher = $environment->getEventDispatcher();
     $translator = $environment->getTranslator();
     $propExtra = $propInfo->getExtra();
     $assetsPath = 'assets/mootools/colorpicker/' . $GLOBALS['TL_ASSETS']['COLORPICKER'] . '/images/';
     if (array_key_exists('colorpicker', $propExtra) && $propExtra['colorpicker']) {
         $pickerText = $translator->translate('colorpicker', 'MSC');
         $event = new GenerateHtmlEvent('pickcolor.gif', $pickerText, sprintf('style="%s" title="%s" id="moo_%s"', 'vertical-align:top;cursor:pointer', specialchars($pickerText), $propInfo->getName()));
         $dispatcher->dispatch(ContaoEvents::IMAGE_GET_HTML, $event);
         // Support single fields as well (see contao/core#5240)
         $strKey = $propExtra['multiple'] ? $propInfo->getName() . '_0' : $propInfo->getName();
         $wizard .= sprintf(' %1$s <script>var cl;window.addEvent("domready", function() { new MooRainbow("moo_%2$s", {' . 'id: "ctrl_%3$s", startColor: ((cl = $("ctrl_%3$s").value.hexToRgb(true)) ? cl : [255, 0, 0]),' . 'imgPath: "%4$s", onComplete: function(color) {$("ctrl_%3$s").value = color.hex.replace("#", "");}});' . '});</script>', $event->getHtml(), $propInfo->getName(), $strKey, $assetsPath);
     }
     return $wizard;
 }
 /**
  * @param EnvironmentInterface $environment
  * @param array                $options
  *
  * @return array
  * @SuppressWarnings(PHPMD.LongVariables)
  */
 public function getRecipientPropertiesOptions(EnvironmentInterface $environment, $options = array())
 {
     if (!is_array($options)) {
         $options = (array) $options;
     }
     global $container;
     $eventDispatcher = $environment->getEventDispatcher();
     $loadDataContainerEvent = new LoadDataContainerEvent('tl_member');
     $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_LOAD_DATA_CONTAINER, $loadDataContainerEvent);
     $loadLanguageFileEvent = new LoadLanguageFileEvent('tl_member');
     $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, $loadLanguageFileEvent);
     /** @var SuperglobalsService $superglobals */
     $superglobals = $container['avisota.superglobals'];
     foreach ($superglobals->getFromDataContainer('tl_members/fields') as $field => $config) {
         $options[$field] = is_array($config['label']) ? $config['label'][0] : $field;
     }
     return $options;
 }
예제 #5
0
 /**
  * Decode a value from native data of the data provider to the widget via event.
  *
  * @param EnvironmentInterface $environment The environment.
  *
  * @param ModelInterface       $model       The model.
  *
  * @param string               $property    The property.
  *
  * @param mixed                $value       The value of the property.
  *
  * @return mixed
  */
 private static function decodeValue($environment, $model, $property, $value)
 {
     $event = new DecodePropertyValueForWidgetEvent($environment, $model);
     $event->setProperty($property)->setValue($value);
     $environment->getEventDispatcher()->dispatch(sprintf('%s', $event::NAME), $event);
     return $event->getValue();
 }
예제 #6
0
 /**
  * Redirect to edit mask.
  *
  * @param EnvironmentInterface $environment   The environment.
  * @param ModelIdInterface     $copiedModelId The model id.
  *
  * @return void
  */
 protected function redirect($environment, $copiedModelId)
 {
     // Build a clean url to remove the copy related arguments instad of using the AddToUrlEvent.
     $url = new BackendUrlBuilder();
     $url->setPath('contao/main.php')->setQueryParameter('do', $environment->getInputProvider()->getParameter('do'))->setQueryParameter('table', $copiedModelId->getDataProviderName())->setQueryParameter('act', 'edit')->setQueryParameter('id', $copiedModelId->getSerialized());
     $redirectEvent = new RedirectEvent($url->getUrl());
     $environment->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_REDIRECT, $redirectEvent);
 }
예제 #7
0
 /**
  * Get the breadcrumb navigation via event.
  *
  * @param EnvironmentInterface $environment The environment.
  *
  * @return string
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 protected function breadcrumb(EnvironmentInterface $environment)
 {
     $event = new GetBreadcrumbEvent($environment);
     $environment->getEventDispatcher()->dispatch($event::NAME, $event);
     $arrReturn = $event->getElements();
     if (!is_array($arrReturn) || count($arrReturn) == 0) {
         return null;
     }
     $GLOBALS['TL_CSS'][] = 'system/modules/dc-general/html/css/generalBreadcrumb.css';
     $objTemplate = new ContaoBackendViewTemplate('dcbe_general_breadcrumb');
     $objTemplate->elements = $arrReturn;
     return $objTemplate->parse();
 }
예제 #8
0
 /**
  * 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;
     }
 }
예제 #9
0
 /**
  * Check if the language has been switched.
  *
  * If so, the value in the session will be updated and the page reloaded.
  *
  * @param EnvironmentInterface $environment The environment.
  *
  * @return void
  */
 private function checkLanguageSubmit($environment)
 {
     $sessionStorage = $environment->getSessionStorage();
     $inputProvider = $environment->getInputProvider();
     if ($inputProvider->getValue('FORM_SUBMIT') !== 'language_switch') {
         return;
     }
     $modelId = $inputProvider->getParameter('id') && $inputProvider->getParameter('id') ? IdSerializer::fromSerialized($inputProvider->getParameter('id'))->getId() : null;
     $languages = $environment->getController()->getSupportedLanguages($modelId);
     $providerName = $environment->getDataDefinition()->getName();
     // Get/Check the new language.
     if ($inputProvider->hasValue('language') && array_key_exists($inputProvider->getValue('language'), $languages)) {
         $session['ml_support'][$providerName][$modelId] = $inputProvider->getValue('language');
         $sessionStorage->set('dc_general', $session);
     }
     $environment->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_RELOAD, new ReloadEvent());
 }
예제 #10
0
 /**
  * Redirects to the real back end module.
  *
  * @param EnvironmentInterface $environment The environment.
  *
  * @return void
  */
 public static function redirectHome(EnvironmentInterface $environment)
 {
     $input = $environment->getInputProvider();
     if ($input->hasParameter('table') && $input->hasParameter('pid')) {
         if ($input->hasParameter('pid')) {
             $event = new RedirectEvent(sprintf('contao/main.php?do=%s&table=%s&pid=%s', $input->getParameter('do'), $input->getParameter('table'), $input->getParameter('pid')));
         } else {
             $event = new RedirectEvent(sprintf('contao/main.php?do=%s&table=%s', $input->getParameter('do'), $input->getParameter('table')));
         }
     } else {
         $event = new RedirectEvent(sprintf('contao/main.php?do=%s', $input->getParameter('do')));
     }
     $environment->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_REDIRECT, $event);
 }
예제 #11
0
 /**
  * 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);
     }
 }
 /**
  * Create the edit mask.
  *
  * @param EnvironmentInterface $environment   The view in use.
  *
  * @param ModelInterface       $model         The model with the current data.
  *
  * @param ModelInterface       $originalModel The data from the original data.
  *
  * @param callable             $preFunction   The function to call before saving an item.
  *
  * @param callable             $postFunction  The function to call after saving an item.
  */
 public function __construct($environment, $model, $originalModel, $preFunction, $postFunction)
 {
     $providerName = $model->getProviderName();
     $this->environment = $environment;
     $this->translator = $environment->getTranslator();
     $this->dispatcher = $environment->getEventDispatcher();
     $this->definition = $environment->getDataDefinition();
     $this->modelProvider = $this->definition->getDataProviderDefinition()->getInformation($providerName);
     $this->model = $model;
     $this->originalModel = $originalModel;
     $this->preFunction = $preFunction;
     $this->postFunction = $postFunction;
 }
 /**
  * Get special labels.
  *
  * @param EnvironmentInterface $environment The environment.
  *
  * @param PropertyInterface    $propInfo    The property for which the options shall be retrieved.
  *
  * @param ModelInterface       $model       The model.
  *
  * @return string
  */
 private function getOptionsForWidget(EnvironmentInterface $environment, PropertyInterface $propInfo, ModelInterface $model)
 {
     $dispatcher = $environment->getEventDispatcher();
     $options = $propInfo->getOptions();
     $event = new GetPropertyOptionsEvent($environment, $model);
     $event->setPropertyName($propInfo->getName());
     $event->setOptions($options);
     $dispatcher->dispatch(GetPropertyOptionsEvent::NAME, $event);
     if ($event->getOptions() !== $options) {
         return $event->getOptions();
     }
     return $options;
 }
예제 #14
0
 /**
  * Obtain the values of a property within a dc-general instance.
  *
  * @param IMetaModel           $metaModel   The metamodel instance to obtain the values from.
  *
  * @param EnvironmentInterface $environment The environment used in the input screen table dc-general.
  *
  * @param IAttribute           $attribute   The attribute to obtain the values for.
  *
  * @return array
  */
 private function getOptionsViaDcGeneral($metaModel, $environment, $attribute)
 {
     $factory = new DcGeneralFactory();
     $dcGeneral = $factory->setContainerName($metaModel->getTableName())->setEventDispatcher($environment->getEventDispatcher())->setTranslator($environment->getTranslator())->createDcGeneral();
     $subEnv = $dcGeneral->getEnvironment();
     $optEv = new GetPropertyOptionsEvent($subEnv, $subEnv->getDataProvider()->getEmptyModel());
     $optEv->setPropertyName($attribute->getColName());
     $subEnv->getEventDispatcher()->dispatch(GetPropertyOptionsEvent::NAME, $optEv);
     $options = $optEv->getOptions();
     return $options;
 }
예제 #15
0
 /**
  * Redirect to the child table.
  *
  * @param EnvironmentInterface $environment The environment.
  * @param boolean              $doNotCopy   The boolean do not copy.
  *
  * @return void
  */
 protected function redirectToChildTable(EnvironmentInterface $environment, $doNotCopy = false)
 {
     $redirectUrl = new BackendUrlBuilder();
     $redirectUrl->setPath('contao/main.php')->setQueryParameter('do', $environment->getInputProvider()->getParameter('do'));
     if ($doNotCopy === false) {
         $redirectUrl->setQueryParameter('act', $environment->getInputProvider()->getParameter('act'))->setQueryParameter('ctable', $environment->getInputProvider()->getParameter('ctable'))->setQueryParameter('table', $environment->getInputProvider()->getParameter('ctable'))->setQueryParameter('id', $environment->getInputProvider()->getParameter('id'))->setQueryParameter('pid', $environment->getInputProvider()->getParameter('id'));
     }
     if ($doNotCopy) {
         // TODO go to the right table
         /*$redirectUrl
           ->setQueryParameter('act', 'edit')
           ->setQueryParameter('table', $environment->getInputProvider()->getParameter('table'))
           ->setQueryParameter('pid', $environment->getInputProvider()->getParameter('id'));*/
     }
     $redirectEvent = new RedirectEvent($redirectUrl->getUrl());
     $environment->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_REDIRECT, $redirectEvent);
 }