示例#1
0
 /**
  * {@inheritdoc}
  */
 public function generate()
 {
     $values = array();
     $icons = array();
     if (!empty($this->varValue)) {
         $files = \FilesModel::findMultipleByUuids((array) $this->varValue);
         $this->renderList($icons, $files, $this->isGallery || $this->isDownloads);
         $icons = $this->applySorting($icons);
         // PHP 7 compatibility, see https://github.com/contao/core-bundle/issues/309
         if (version_compare(VERSION . '.' . BUILD, '3.5.5', '>=')) {
             $mapFunc = 'StringUtil::binToUuid';
         } else {
             $mapFunc = 'String::binToUuid';
         }
         foreach ($files as $model) {
             $values[] = call_user_func($mapFunc, $model->uuid);
         }
     }
     $template = new ContaoBackendViewTemplate($this->subTemplate);
     $buffer = $template->setTranslator($this->getEnvironment()->getTranslator())->set('name', $this->strName)->set('id', $this->strId)->set('value', implode(',', $values))->set('hasOrder', $this->orderField != '' && is_array($this->orderFieldValue))->set('icons', $icons)->set('isGallery', $this->isGallery)->set('orderId', $this->orderId)->set('link', $this->generateLink($values))->parse();
     if (!\Environment::get('isAjaxRequest')) {
         $buffer = '<div>' . $buffer . '</div>';
     }
     return $buffer;
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function generate()
 {
     $values = array();
     $icons = array();
     if (!empty($this->varValue)) {
         $files = \FilesModel::findMultipleByUuids((array) $this->varValue);
         $this->renderList($values, $icons, $files, $this->isGallery || $this->isDownloads);
         $icons = $this->applySorting($icons);
     }
     $template = new ContaoBackendViewTemplate($this->subTemplate);
     $buffer = $template->setTranslator($this->getEnvironment()->getTranslator())->set('name', $this->strName)->set('id', $this->strId)->set('value', implode(',', array_map('String::binToUuid', $values)))->set('hasOrder', $this->orderField != '' && is_array($this->orderFieldValue))->set('icons', $icons)->set('isGallery', $this->isGallery)->set('orderId', $this->orderId)->set('link', $this->generateLink($values))->parse();
     if (!\Environment::get('isAjaxRequest')) {
         $buffer = '<div>' . $buffer . '</div>';
     }
     return $buffer;
 }
示例#3
0
 /**
  * Render the panels.
  *
  * @param array $ignoredPanels A list with ignored elements [Optional].
  *
  * @throws DcGeneralRuntimeException When no information of panels can be obtained from the data container.
  *
  * @return string
  */
 public function render($ignoredPanels = array())
 {
     // TODO: Determine list of ignored panels by triggering an event.
     if ($this->view->getPanel() === null) {
         throw new DcGeneralRuntimeException('No panel information stored in data container.');
     }
     $environment = $this->getEnvironment();
     $dispatcher = $environment->getEventDispatcher();
     $panels = array();
     foreach ($this->view->getPanel() as $panel) {
         $panels[] = $this->renderPanelRow($panel, $ignoredPanels);
     }
     if (count($panels)) {
         $template = new ContaoBackendViewTemplate('dcbe_general_panel');
         $themeEvent = new GetThemeEvent();
         $dispatcher->dispatch(ContaoEvents::BACKEND_GET_THEME, $themeEvent);
         $template->set('action', ampersand($environment->getInputProvider()->getRequestUrl(), true))->set('theme', $themeEvent->getTheme())->set('panel', $panels);
         return $template->parse();
     }
     return '';
 }
    /**
     * Render the widget for the named property.
     *
     * @param string           $property     The name of the property for which the widget shall be rendered.
     *
     * @param bool             $ignoreErrors Flag if the error property of the widget shall get cleared prior rendering.
     *
     * @param PropertyValueBag $inputValues  The input values to use (optional).
     *
     * @return string
     *
     * @throws DcGeneralRuntimeException For unknown properties.
     */
    public function renderWidget($property, $ignoreErrors = false, PropertyValueBag $inputValues = null)
    {
        $environment = $this->getEnvironment();
        $definition = $environment->getDataDefinition();
        $propertyDefinitions = $definition->getPropertiesDefinition();
        $propInfo = $propertyDefinitions->getProperty($property);
        $propExtra = $propInfo->getExtra();
        $widget = $this->getWidget($property, $inputValues);
        /** @var \Contao\Widget $widget */
        if (!$widget) {
            throw new DcGeneralRuntimeException('No widget for property ' . $property);
        }
        if ($ignoreErrors) {
            // Clean the errors array and fix up the CSS class.
            $reflection = new \ReflectionProperty(get_class($widget), 'arrErrors');
            $reflection->setAccessible(true);
            $reflection->setValue($widget, array());
            $reflection = new \ReflectionProperty(get_class($widget), 'strClass');
            $reflection->setAccessible(true);
            $reflection->setValue($widget, str_replace('error', '', $reflection->getValue($widget)));
        } else {
            if ($inputValues && $inputValues->hasPropertyValue($property) && $inputValues->isPropertyValueInvalid($property)) {
                foreach ($inputValues->getPropertyValueErrors($property) as $error) {
                    $widget->addError($error);
                }
            }
        }
        $strDatePicker = '';
        if (isset($propExtra['datepicker'])) {
            $strDatePicker = $this->buildDatePicker($widget);
        }
        $objTemplateFoo = new ContaoBackendViewTemplate('dcbe_general_field');
        $objTemplateFoo->setData(array('strName' => $property, 'strClass' => $widget->tl_class, 'widget' => $widget->parse(), 'hasErrors' => $widget->hasErrors(), 'strDatepicker' => $strDatePicker, 'blnUpdate' => false, 'strHelp' => $this->generateHelpText($property), 'strId' => $widget->id));
        $buffer = $objTemplateFoo->parse();
        if (isset($propExtra['rte']) && strncmp($propExtra['rte'], 'tiny', 4) === 0) {
            $propertyId = 'ctrl_' . $property;
            $buffer .= <<<EOF
<script>tinyMCE.execCommand('mceAddControl', false, '{$propertyId}');\$('{$propertyId}').erase('required');</script>
EOF;
        }
        return $buffer;
    }
示例#5
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();
 }
示例#6
0
 /**
  * Create a new instance of ContaoBackendViewTemplate with the template file of the given name.
  *
  * @param string $strTemplate Name of the template to create.
  *
  * @return ContaoBackendViewTemplate
  */
 protected function getTemplate($strTemplate)
 {
     $template = new ContaoBackendViewTemplate($strTemplate);
     $template->setTranslator($this->getEnvironment()->getTranslator());
     return $template;
 }
示例#7
0
 /**
  * Create the edit mask.
  *
  * @return string
  *
  * @throws DcGeneralRuntimeException         If the data container is not editable, closed.
  *
  * @throws DcGeneralInvalidArgumentException If an unknown property is encountered in the palette.
  *
  * @SuppressWarnings(PHPMD.LongVariable)
  */
 public function execute()
 {
     $environment = $this->getEnvironment();
     $definition = $this->getDataDefinition();
     $dataProvider = $environment->getDataProvider($this->model->getProviderName());
     $dataProviderDefinition = $definition->getDataProviderDefinition();
     $dataProviderInformation = $dataProviderDefinition->getInformation($this->model->getProviderName());
     $inputProvider = $environment->getInputProvider();
     $palettesDefinition = $definition->getPalettesDefinition();
     $blnSubmitted = $inputProvider->getValue('FORM_SUBMIT') === $definition->getName();
     $blnIsAutoSubmit = $inputProvider->getValue('SUBMIT_TYPE') === 'auto';
     $widgetManager = new ContaoWidgetManager($environment, $this->model);
     $this->checkEditable($this->model);
     $this->checkCreatable($this->model);
     $environment->getEventDispatcher()->dispatch(PreEditModelEvent::NAME, new PreEditModelEvent($environment, $this->model));
     $environment->getEventDispatcher()->dispatch(DcGeneralEvents::ENFORCE_MODEL_RELATIONSHIP, new EnforceModelRelationshipEvent($this->getEnvironment(), $this->model));
     // Pass 1: Get the palette for the values stored in the model.
     $palette = $palettesDefinition->findPalette($this->model);
     $propertyValues = $this->processInput($widgetManager);
     if ($blnSubmitted && $propertyValues) {
         // Pass 2: Determine the real palette we want to work on if we have some data submitted.
         $palette = $palettesDefinition->findPalette($this->model, $propertyValues);
         // Update the model - the model might add some more errors to the propertyValueBag via exceptions.
         $this->getEnvironment()->getController()->updateModelFromPropertyBag($this->model, $propertyValues);
     }
     $fieldSets = $this->buildFieldSet($widgetManager, $palette, $propertyValues);
     if (!$blnIsAutoSubmit && $blnSubmitted && empty($this->errors)) {
         if ($this->doPersist()) {
             $this->handleSubmit($this->model);
         }
     }
     $objTemplate = new ContaoBackendViewTemplate('dcbe_general_edit');
     $objTemplate->setData(array('fieldsets' => $fieldSets, 'versions' => $dataProviderInformation->isVersioningEnabled() ? $dataProvider->getVersions($this->model->getId()) : null, 'subHeadline' => $this->getHeadline(), 'table' => $definition->getName(), 'enctype' => 'multipart/form-data', 'error' => $this->errors, 'editButtons' => $this->getEditButtons(), 'noReload' => (bool) $this->errors, 'breadcrumb' => $this->breadcrumb));
     if (in_array('ContaoCommunityAlliance\\DcGeneral\\Data\\MultiLanguageDataProviderInterface', class_implements($environment->getDataProvider($this->model->getProviderName())))) {
         /** @var MultiLanguageDataProviderInterface $dataProvider */
         $langsNative = array();
         require TL_ROOT . '/system/config/languages.php';
         $objTemplate->set('languages', $environment->getController()->getSupportedLanguages($this->model->getId()))->set('language', $dataProvider->getCurrentLanguage())->set('languageHeadline', $langsNative[$dataProvider->getCurrentLanguage()]);
     } else {
         $objTemplate->set('languages', null)->set('languageHeadline', '');
     }
     return $objTemplate->parse();
 }
示例#8
0
 /**
  * Handle the show event.
  *
  * @return void
  *
  * @throws DcGeneralRuntimeException  The error.
  */
 public function process()
 {
     $environment = $this->getEnvironment();
     if ($environment->getDataDefinition()->getBasicDefinition()->isEditOnlyMode()) {
         $this->getEvent()->setResponse($environment->getView()->edit($this->getEvent()->getAction()));
         return;
     }
     $translator = $environment->getTranslator();
     $modelId = ModelId::fromSerialized($environment->getInputProvider()->getParameter('id'));
     $dataProvider = $environment->getDataProvider($modelId->getDataProviderName());
     $model = $this->getModel();
     $data = $this->convertModel($model, $environment);
     $headline = $this->getHeadline($model);
     $template = new ContaoBackendViewTemplate('dcbe_general_show');
     $template->set('headline', $headline)->set('arrFields', $data['values'])->set('arrLabels', $data['labels']);
     if ($dataProvider instanceof MultiLanguageDataProviderInterface) {
         $template->set('languages', $environment->getController()->getSupportedLanguages($model->getId()))->set('currentLanguage', $dataProvider->getCurrentLanguage())->set('languageSubmit', specialchars($translator->translate('MSC.showSelected')))->set('backBT', specialchars($translator->translate('MSC.backBT')));
     } else {
         $template->set('languages', null);
     }
     $this->getEvent()->setResponse($template->parse());
 }
示例#9
0
 /**
  * Generate the tree view for a given collection.
  *
  * @param CollectionInterface $objCollection The collection to iterate over.
  *
  * @param string              $treeClass     The class to use for the tree.
  *
  * @return string
  */
 protected function generateTreeView($objCollection, $treeClass)
 {
     $arrHtml = array();
     foreach ($objCollection as $objModel) {
         /** @var ModelInterface $objModel */
         $strToggleID = $objModel->getProviderName() . '_' . $treeClass . '_' . $objModel->getId();
         $arrHtml[] = $this->parseModel($objModel, $strToggleID);
         if ($objModel->getMeta($objModel::HAS_CHILDREN) && $objModel->getMeta($objModel::SHOW_CHILDREN)) {
             $template = new ContaoBackendViewTemplate('widget_treepicker_child');
             $subHtml = '';
             foreach ($objModel->getMeta($objModel::CHILD_COLLECTIONS) as $objCollection) {
                 $subHtml .= $this->generateTreeView($objCollection, $treeClass);
             }
             $template->setTranslator($this->getEnvironment()->getTranslator())->set('objParentModel', $objModel)->set('strToggleID', $strToggleID)->set('strHTML', $subHtml)->set('strTable', $objModel->getProviderName());
             $arrHtml[] = $template->parse();
         }
     }
     return implode("\n", $arrHtml);
 }