예제 #1
0
 /**
  * Retrieve the MetaModel attached to the model condition setting.
  *
  * @param EnvironmentInterface $interface The environment.
  *
  * @return \MetaModels\IMetaModel
  */
 public function getMetaModel(EnvironmentInterface $interface)
 {
     $metaModelId = $this->getDatabase()->prepare('SELECT id FROM tl_metamodel WHERE
             id=(SELECT pid FROM tl_metamodel_dca WHERE
             id=(SELECT pid FROM tl_metamodel_dcasetting WHERE id=?))')->execute(ModelId::fromSerialized($interface->getInputProvider()->getParameter('pid'))->getId());
     return $this->getMetaModelById($metaModelId->id);
 }
예제 #2
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->setEventPropagator($environment->getEventPropagator());
     $factory->setTranslator($environment->getTranslator());
     $factory->setEnvironmentClassName(get_class($environment));
     $factory->setContainerClassName(get_class($environment->getDataDefinition()));
     return $factory;
 }
예제 #3
0
파일: Base.php 프로젝트: menatwork/synccto
 /**
  * Check if the current call is my context.
  *
  * @param EnvironmentInterface $environment The container with the env.
  *
  * @param null|string          $overwrite   Set a overwrite for the data provider name.
  *
  * @return bool Return false if this class should not do something in this context.
  */
 public function isRightContext($environment, $overwrite = null)
 {
     if ($overwrite !== null && !$environment->hasDataProvider($overwrite)) {
         return false;
     } else {
         if ($overwrite === null && !$environment->hasDataProvider($this->getContextProviderName())) {
             return false;
         }
     }
     return true;
 }
예제 #4
0
 /**
  * Load the parent model for the current list.
  *
  * @param InputProviderInterface $input       The input provider.
  *
  * @param EnvironmentInterface   $environment The environment.
  *
  * @return ModelInterface|null
  */
 protected function loadParentModel(InputProviderInterface $input, EnvironmentInterface $environment)
 {
     if (!$input->hasParameter('pid')) {
         return null;
     }
     $pid = ModelId::fromSerialized($input->getParameter('pid'));
     if (!($dataProvider = $environment->getDataProvider($pid->getDataProviderName()))) {
         return null;
     }
     if ($parent = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($pid->getId()))) {
         return $parent;
     }
     return null;
 }
예제 #5
0
 /**
  * {@inheritDoc}
  */
 public function getBreadcrumbElements(EnvironmentInterface $environment, $elements)
 {
     $input = $environment->getInputProvider();
     if (!$this->isActiveTable('tl_metamodel_filter', $input)) {
         $this->filterId = $this->extractIdFrom($environment, 'pid');
     } else {
         $this->metamodelId = $this->extractIdFrom($environment, 'pid');
     }
     if (!isset($this->metamodelId)) {
         $this->metamodelId = $this->getFilter()->pid;
     }
     $elements = parent::getBreadcrumbElements($environment, $elements);
     $elements[] = array('url' => $this->generateUrl('tl_metamodel_filter', $this->seralizeId('tl_metamodel', $this->metamodelId)), 'text' => sprintf($this->getBreadcrumbLabel($environment, 'tl_metamodel_filter'), $this->getMetaModel()->getName()), 'icon' => $this->getBaseUrl() . '/system/modules/metamodels/assets/images/icons/filter.png');
     return $elements;
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function showAll(Action $action)
 {
     if ($this->environment->getDataDefinition()->getBasicDefinition()->isEditOnlyMode()) {
         return $this->edit($action);
     }
     return sprintf($this->notImplMsg, 'showAll - Mode ' . $this->environment->getDataDefinition()->getBasicDefinition()->getMode());
 }
 /**
  * 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;
 }
예제 #8
0
 /**
  * Instantiates and adds the data providers implementing ContaoDataProviderInformation to the environment.
  *
  * @param EnvironmentInterface $environment The environment to populate.
  *
  * @return void
  *
  * @throws DcGeneralRuntimeException When a data provider has already been added to the environment.
  */
 public function populate(EnvironmentInterface $environment)
 {
     $definition = $environment->getDataDefinition();
     foreach ($definition->getDataProviderDefinition() as $information) {
         if ($information instanceof ContaoDataProviderInformation) {
             if ($environment->hasDataProvider($information->getName())) {
                 throw new DcGeneralRuntimeException(sprintf('Data provider %s already added to environment.', $information->getName()));
             }
             $providerClass = new \ReflectionClass($information->getClassName());
             /** @var DataProviderInterface $dataProvider */
             $dataProvider = $providerClass->newInstance();
             if ($initializationData = $information->getInitializationData()) {
                 $dataProvider->setBaseConfig($initializationData);
             }
             $environment->addDataProvider($information->getName(), $dataProvider);
         }
     }
 }
예제 #9
0
 /**
  * {@inheritDoc}
  */
 public function populate(EnvironmentInterface $environment)
 {
     if (!$environment->getSessionStorage()) {
         $environment->setSessionStorage(new SessionStorage('DC_GENERAL_' . strtoupper($environment->getDataDefinition()->getName())));
     }
     if (!$environment->getInputProvider()) {
         $environment->setInputProvider(new InputProvider());
     }
     if (!$environment->getClipboard()) {
         $environment->setClipboard(new Clipboard());
     }
     if (!$environment->getBaseConfigRegistry()) {
         $baseConfigRegistry = new BaseConfigRegistry();
         $baseConfigRegistry->setEnvironment($environment);
         $environment->setBaseConfigRegistry($baseConfigRegistry);
     }
     $this->populateController($environment);
 }
 /**
  * @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;
 }
 /**
  * Populate the file picker $GLOBALS['TL_DCA'] to make the contao/file.php happy.
  *
  * The backend file contao/file.php is using hard coded direct array access on the TL_DCA array therefore we need to
  * dump all of this there.
  *
  * @param EnvironmentInterface $environment The environment.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 protected function populateFilePickers(EnvironmentInterface $environment)
 {
     $definition = $environment->getDataDefinition();
     $name = $definition->getName();
     if (!isset($GLOBALS['TL_DCA'])) {
         $GLOBALS['TL_DCA'] = array();
     }
     if (!isset($GLOBALS['TL_DCA'][$name])) {
         $GLOBALS['TL_DCA'][$name] = array();
     }
     if (!isset($GLOBALS['TL_DCA'][$name]['fields'])) {
         $GLOBALS['TL_DCA'][$name]['fields'] = array();
     }
     $dca =& $GLOBALS['TL_DCA'][$name]['fields'];
     foreach ($environment->getDataDefinition()->getPropertiesDefinition()->getProperties() as $property) {
         if ($property->getWidgetType() == 'fileTree') {
             $dca[$property->getName()]['eval'] = $property->getExtra();
         }
     }
 }
예제 #12
0
 /**
  * Create the environment.
  *
  * @return void
  */
 private function createEnvironment()
 {
     $container = new DefaultContainer('workflow_data');
     $container->setPropertiesDefinition(new DefaultPropertiesDefinition());
     $container->setBasicDefinition(new DefaultBasicDefinition());
     $this->environment = new DefaultEnvironment();
     $this->environment->setDataDefinition($container);
     $this->environment->setInputProvider(new InputProvider());
     $controller = new DefaultController();
     $controller->setEnvironment($this->environment);
     $this->environment->setController($controller);
 }
 /**
  * Handle the persisting of the currently loaded model.
  *
  * @return void
  */
 private function doPersist()
 {
     if (!$this->model->getMeta(ModelInterface::IS_CHANGED)) {
         return;
     }
     $this->handlePrePersist();
     // FIXME: manual sorting property handling is not enabled here as it originates from the backend defininiton.
     // Save the model.
     $dataProvider = $this->environment->getDataProvider($this->model->getProviderName());
     $dataProvider->save($this->model);
     $this->handlePostPersist();
     $this->storeVersion($this->model);
 }
 /**
  * Retrieve the instance of a widget for the given property.
  *
  * @param string           $property Name of the property for which the widget shall be retrieved.
  *
  * @param PropertyValueBag $valueBag The input values to use (optional).
  *
  * @return \Widget
  *
  * @throws DcGeneralRuntimeException         When No widget could be build.
  * @throws DcGeneralInvalidArgumentException When property is not defined in the property definitions.
  */
 public function getWidget($property, PropertyValueBag $valueBag = null)
 {
     $environment = $this->getEnvironment();
     $dispatcher = $environment->getEventDispatcher();
     $propertyDefinitions = $environment->getDataDefinition()->getPropertiesDefinition();
     if (!$propertyDefinitions->hasProperty($property)) {
         throw new DcGeneralInvalidArgumentException('Property ' . $property . ' is not defined in propertyDefinitions.');
     }
     $model = clone $this->model;
     $model->setId($this->model->getId());
     if ($valueBag) {
         $values = new PropertyValueBag($valueBag->getArrayCopy());
         $this->environment->getController()->updateModelFromPropertyBag($model, $values);
     }
     $propertyDefinition = $propertyDefinitions->getProperty($property);
     $event = new BuildWidgetEvent($environment, $model, $propertyDefinition);
     $dispatcher->dispatch(DcGeneralFrontendEvents::BUILD_WIDGET, $event);
     if (!$event->getWidget()) {
         throw new DcGeneralRuntimeException(sprintf('Widget was not build for property %s::%s.', $this->model->getProviderName(), $property));
     }
     return $event->getWidget();
 }
 /**
  * Create a controller instance in the environment if none has been defined yet.
  *
  * @param EnvironmentInterface $environment The environment to populate.
  *
  * @return void
  *
  * @internal
  */
 public function populateController(EnvironmentInterface $environment)
 {
     // Already populated, get out then.
     if ($environment->getController()) {
         return;
     }
     $definition = $environment->getDataDefinition();
     // If we encounter an extended definition, that one may override.
     if (!$definition->hasDefinition(ExtendedDca::NAME)) {
         return;
     }
     /** @var ExtendedDca $extendedDefinition */
     $extendedDefinition = $definition->getDefinition(ExtendedDca::NAME);
     $class = $extendedDefinition->getControllerClass();
     if (!$class) {
         return;
     }
     $controllerClass = new \ReflectionClass($class);
     /** @var ControllerInterface $controller */
     $controller = $controllerClass->newInstance();
     $controller->setEnvironment($environment);
     $environment->setController($controller);
 }
예제 #16
0
 /**
  * {@inheritDoc}
  */
 public function populate(EnvironmentInterface $environment)
 {
     if (!$environment->getInputProvider()) {
         $environment->setInputProvider(new InputProvider());
     }
     if (!$environment->getClipboard()) {
         $environment->setClipboard(new DefaultClipboard());
     }
     $this->populateController($environment);
 }
예제 #17
0
 /**
  * Determine the toggle state of a toggle command.
  *
  * @param ToggleCommandInterface $command The toggle command.
  *
  * @param ModelInterface         $model   The model in scope.
  *
  * @return bool
  */
 private function isTogglerInActiveState($command, $model)
 {
     $dataProvider = $this->environment->getDataProvider($model->getProviderName());
     if ($command instanceof TranslatedToggleCommandInterface && $dataProvider instanceof MultiLanguageDataProviderInterface) {
         $language = $dataProvider->getCurrentLanguage();
         $dataProvider->setCurrentLanguage($command->getLanguage());
         $propModel = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($model->getId())->setFields($command->getToggleProperty()));
         $dataProvider->setCurrentLanguage($language);
     } else {
         $propModel = $model;
     }
     if ($command->isInverse()) {
         return !$propModel->getProperty($command->getToggleProperty());
     }
     return (bool) $propModel->getProperty($command->getToggleProperty());
 }
예제 #18
0
 /**
  * Handle the paste into and after buttons.
  *
  * @param GetPasteButtonEvent $event The event.
  *
  * @return void
  *
  * @throws \RuntimeException When more than one model is contained within the clipboard.
  */
 public function handle(GetPasteButtonEvent $event)
 {
     $this->circularReference = $event->isCircularReference();
     $this->environment = $event->getEnvironment();
     $this->provider = $this->environment->getDataProvider();
     $this->providerName = $this->provider->getEmptyModel()->getProviderName();
     $clipboard = $this->environment->getClipboard();
     $this->currentModel = $event->getModel();
     $this->disablePI = true;
     $this->disablePA = true;
     // Only run for a MetaModels and if both values already disabled return here.
     if (substr($this->providerName, 0, 3) !== 'mm_' || $event->isPasteIntoDisabled() && $event->isPasteAfterDisabled()) {
         return;
     }
     $this->checkForAction($clipboard, 'copy');
     $this->checkForAction($clipboard, 'create');
     $this->checkForAction($clipboard, 'cut');
     $event->setPasteAfterDisabled($this->disablePA)->setPasteIntoDisabled($this->disablePI);
 }
예제 #19
0
 /**
  * Retrieve the MetaModel attached to the model filter setting.
  *
  * @param EnvironmentInterface $environment The environment.
  *
  * @return \MetaModels\IMetaModel
  */
 public function getMetaModel(EnvironmentInterface $environment)
 {
     $metaModelId = $this->getDatabase()->prepare('SELECT id FROM tl_metamodel WHERE id=(SELECT pid FROM tl_metamodel_dca WHERE id=?)')->execute(ModelId::fromSerialized($environment->getInputProvider()->getParameter('pid'))->getId());
     /** @noinspection PhpUndefinedFieldInspection */
     return $this->getMetaModelById($metaModelId->id);
 }
예제 #20
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();
 }
예제 #21
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
  */
 public function decodeValue($environment, $model, $property, $value)
 {
     $event = new DecodePropertyValueForWidgetEvent($environment, $model);
     $event->setProperty($property)->setValue($value);
     $environment->getEventPropagator()->propagate($event::NAME, $event, array($environment->getDataDefinition()->getName(), $property));
     return $event->getValue();
 }
예제 #22
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);
 }
 /**
  * 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');
 }
예제 #24
0
파일: Helper.php 프로젝트: zonky2/core
 /**
  * Create a widget for naming contexts. Use the language and translation information from the MetaModel.
  *
  * @param EnvironmentInterface $environment   The environment.
  *
  * @param PropertyInterface    $property      The property.
  *
  * @param IMetaModel           $metaModel     The MetaModel.
  *
  * @param string               $languageLabel The label to use for the language indicator.
  *
  * @param string               $valueLabel    The label to use for the input field.
  *
  * @param bool                 $isTextArea    If true, the widget will become a textarea, false otherwise.
  *
  * @param array                $arrValues     The values for the widget, needed to highlight the fallback language.
  *
  * @return void
  */
 public static function prepareLanguageAwareWidget(EnvironmentInterface $environment, PropertyInterface $property, IMetaModel $metaModel, $languageLabel, $valueLabel, $isTextArea, $arrValues)
 {
     if (!$metaModel->isTranslated()) {
         $extra = $property->getExtra();
         $extra['tl_class'] .= 'w50';
         $property->setWidgetType('text')->setExtra($extra);
         return;
     }
     $fallback = $metaModel->getFallbackLanguage();
     $languages = self::buildLanguageArray($metaModel, $environment->getTranslator());
     $neededKeys = array_keys($languages);
     // Ensure we have values for all languages present.
     if (array_diff_key(array_keys($arrValues), $neededKeys)) {
         foreach ($neededKeys as $langCode) {
             $arrValues[$langCode] = '';
         }
     }
     $rowClasses = array();
     foreach (array_keys($arrValues) as $langCode) {
         $rowClasses[] = $langCode == $fallback ? 'fallback_language' : 'normal_language';
     }
     $extra = $property->getExtra();
     $extra['minCount'] = $extra['maxCount'] = count($languages);
     $extra['disableSorting'] = true;
     $extra['tl_class'] = 'clr';
     $extra['columnFields'] = array('langcode' => array('label' => $languageLabel, 'exclude' => true, 'inputType' => 'justtextoption', 'options' => $languages, 'eval' => array('rowClasses' => $rowClasses, 'valign' => 'center', 'style' => 'min-width:75px;display:block;')), 'value' => array('label' => $valueLabel, 'exclude' => true, 'inputType' => $isTextArea ? 'textarea' : 'text', 'eval' => array('rowClasses' => $rowClasses, 'style' => 'width:400px;', 'rows' => 3)));
     $property->setWidgetType('multiColumnWizard')->setExtra($extra);
 }
예제 #25
0
 /**
  * Retrieve the instance of a widget for the given property.
  *
  * @param string           $property    Name of the property for which the widget shall be retrieved.
  *
  * @param PropertyValueBag $inputValues The input values to use (optional).
  *
  * @throws DcGeneralInvalidArgumentException When an unknown property has been passed.
  *
  * @return \Widget
  */
 public function getWidget($property, PropertyValueBag $inputValues = null)
 {
     $environment = $this->getEnvironment();
     $defName = $environment->getDataDefinition()->getName();
     $propertyDefinitions = $environment->getDataDefinition()->getPropertiesDefinition();
     if (!$propertyDefinitions->hasProperty($property)) {
         throw new DcGeneralInvalidArgumentException('Property ' . $property . ' is not defined in propertyDefinitions.');
     }
     $event = new BuildWidgetEvent($environment, $this->model, $propertyDefinitions->getProperty($property));
     $environment->getEventPropagator()->propagate($event::NAME, $event, array($defName, $property));
     if ($event->getWidget()) {
         return $event->getWidget();
     }
     $propInfo = $propertyDefinitions->getProperty($property);
     $propExtra = $propInfo->getExtra();
     $varValue = $this->decodeValue($property, $this->model->getProperty($property));
     $xLabel = $this->getXLabel($propInfo);
     $strClass = $GLOBALS['BE_FFL'][$propInfo->getWidgetType()];
     if (!class_exists($strClass)) {
         return null;
     }
     // FIXME TEMPORARY WORKAROUND! To be fixed in the core: Controller::prepareForWidget(..).
     if (in_array($propExtra['rgxp'], array('date', 'time', 'datim')) && !$propExtra['mandatory'] && is_numeric($varValue) && $varValue == 0) {
         $varValue = '';
     }
     // OH: why not $required = $mandatory always? source: DataContainer 226.
     // OH: the whole prepareForWidget(..) thing is an only mess
     // Widgets should parse the configuration by themselves, depending on what they need.
     $propExtra['required'] = $varValue == '' && $propExtra['mandatory'];
     if ($inputValues) {
         $model = clone $this->model;
         $model->setId($this->model->getId());
         $this->environment->getController()->updateModelFromPropertyBag($model, $inputValues);
     } else {
         $model = $this->model;
     }
     $options = $propInfo->getOptions();
     $event = new GetPropertyOptionsEvent($environment, $model);
     $event->setPropertyName($property);
     $event->setOptions($options);
     $environment->getEventPropagator()->propagate($event::NAME, $event, $environment->getDataDefinition()->getName(), $property);
     if ($event->getOptions() !== $options) {
         $options = $event->getOptions();
     }
     $arrConfig = array('inputType' => $propInfo->getWidgetType(), 'label' => array($propInfo->getLabel(), $propInfo->getDescription()), 'options' => $options, 'eval' => $propExtra);
     if (isset($propExtra['reference'])) {
         $arrConfig['reference'] = $propExtra['reference'];
     }
     $event = new GetAttributesFromDcaEvent($arrConfig, $propInfo->getName(), $varValue, $property, $defName, new DcCompat($environment, $this->model, $property));
     $environment->getEventPropagator()->propagate(ContaoEvents::WIDGET_GET_ATTRIBUTES_FROM_DCA, $event, $environment->getDataDefinition()->getName(), $property);
     $arrPrepared = $event->getResult();
     // Bugfix CS: ajax subpalettes are really broken.
     // Therefore we reset to the default checkbox behaviour here and submit the entire form.
     // This way, the javascript needed by the widget (wizards) will be correctly evaluated.
     if ($arrConfig['inputType'] == 'checkbox' && is_array($GLOBALS['TL_DCA'][$defName]['subpalettes']) && in_array($property, array_keys($GLOBALS['TL_DCA'][$defName]['subpalettes'])) && $arrConfig['eval']['submitOnChange']) {
         $arrPrepared['onclick'] = $arrConfig['eval']['submitOnChange'] ? "Backend.autoSubmit('" . $defName . "')" : '';
     }
     $objWidget = new $strClass($arrPrepared);
     // OH: what is this? source: DataContainer 232.
     $objWidget->currentRecord = $this->model->getId();
     $objWidget->wizard .= $xLabel;
     $event = new ManipulateWidgetEvent($environment, $this->model, $propInfo, $objWidget);
     $environment->getEventPropagator()->propagate($event::NAME, $event, array($defName, $property));
     return $objWidget;
 }
예제 #26
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());
 }
예제 #27
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();
 }
예제 #28
0
 public function handleListAction(EnvironmentInterface $environment)
 {
     $input = $environment->getInputProvider();
     $id = IdSerializer::fromSerialized($input->getParameter('id'));
     $repository = EntityHelper::getRepository('Avisota\\Contao:RecipientSource');
     /** @var \Avisota\Contao\Entity\RecipientSource $recipientSourceEntity */
     $recipientSourceEntity = $repository->find($id->getId());
     /** @var RecipientSourceInterface $recipientSource */
     $recipientSource = $GLOBALS['container'][sprintf('avisota.recipientSource.%s', $recipientSourceEntity->getId())];
     if ($input->getValue('page')) {
         /** @var EventDispatcher $eventDispatcher */
         $eventDispatcher = $GLOBALS['container']['event-dispatcher'];
         $addToUrlEvent = new AddToUrlEvent('page=' . (int) $input->getValue('page'));
         $eventDispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, $addToUrlEvent);
         $redirectEvent = new RedirectEvent($addToUrlEvent->getUrl());
         $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, $redirectEvent);
     }
     $total = $recipientSource->countRecipients();
     $page = $input->getParameter('page') ?: 0;
     $pages = ceil($total / 30);
     $recipients = $recipientSource->getRecipients(30, $page * 30);
     $template = new \TwigBackendTemplate('avisota/backend/recipient_source_list');
     $template->total = $total;
     $template->page = $page;
     $template->pages = $pages;
     $template->recipients = $recipients;
     return $template->parse();
 }
예제 #29
0
 /**
  * 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);
 }
예제 #30
0
 /**
  * Retrieve the parameters for the label with attribute name and url parameter.
  *
  * @param EnvironmentInterface $environment The translator in use.
  *
  * @param ModelInterface       $model       The model.
  *
  * @return array
  */
 protected function getLabelParametersNormal(EnvironmentInterface $environment, ModelInterface $model)
 {
     $translator = $environment->getTranslator();
     return array($this->getLabelImage($model), $this->getLabelText($translator, $model), $this->getLabelComment($model, $translator), $model->getProperty('type'));
 }