Exemplo n.º 1
0
 /**
  * Initialize the backend view.
  *
  * @param DataContainer $dataContainer The data container.
  *
  * @return void
  */
 public function initialize($dataContainer)
 {
     if (TL_MODE !== 'BE') {
         return;
     }
     $this->getServiceContainer()->getAssetsManager()->addStylesheet('system/modules/content-node/assets/css/backend.css');
     $callback = $this->definition->get('list/sorting/child_record_callback');
     if (is_array($callback)) {
         $callback[0] = \System::importStatic($callback[0]);
     }
     $renderer = new BackendRenderer($this->registry, $callback);
     $definition = $this->getServiceContainer()->getDcaManager()->get('tl_content');
     $definition->set('list/sorting/child_record_callback', $renderer);
     $parentType = null;
     if ($dataContainer->parentTable === 'tl_content_node') {
         $parent = \ContentModel::findByPk(CURRENT_ID);
         if ($parent && $this->registry->hasNodeType($parent->tye)) {
             $parentType = $this->registry->getNode($parent->type);
         }
     }
     try {
         $restriction = new ContentElementAccess($this->definition, $this->registry, $this->getServiceContainer()->getDatabaseConnection(), $this->getServiceContainer()->getSession(), $this->getServiceContainer()->getInput());
         $restriction->restrict($dataContainer->id, $parentType);
     } catch (AccessDeniedException $e) {
         \Controller::log($e->getMessage(), 'ContentElementAccess::resitrct', TL_ACCESS);
         \Controller::redirect(\Environment::get('script') . '?act=error');
     }
 }
 /**
  * Restrict the content elements.
  *
  * @param int  $contentId The id of the current content element.
  * @param Node $node      The node type.
  *
  * @return void
  * @throws AccessDeniedException When an invalid content element type is accessed.
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public function restrict($contentId, Node $node = null)
 {
     $nodeType = $node ? $node->getName() : null;
     $allowedElements = $this->registry->filterContentElements($GLOBALS['TL_CTE'], $nodeType);
     if (empty($allowedElements)) {
         $this->closeDataContainer();
     } elseif (!in_array($this->definition->get('fields/type/default'), $allowedElements)) {
         $this->setDefaults($allowedElements);
     }
     if ($this->input->get('act') != '' && $this->input->get('act') !== 'select') {
         $GLOBALS['TL_CTE'] = $allowedElements;
         $this->restrictIds($allowedElements, $contentId);
     }
 }
Exemplo n.º 3
0
 /**
  * Generate a child.
  *
  * @param ContentModel $model The model.
  *
  * @return string
  */
 private function generateChild(ContentModel $model)
 {
     $callback = $this->definition->get('list/sorting/child_record_callback');
     if (!$callback) {
         return '';
     }
     if (is_array($callback)) {
         $callback[0] = new $callback[0]();
     }
     if (is_callable($callback)) {
         return call_user_func($callback, $model->row());
     }
     // Invalid callback.
     return '';
 }
Exemplo n.º 4
0
 /**
  * Generate the move button.
  *
  * @param array $row The current row.
  *
  * @return string
  */
 private function generateMoveButton($row)
 {
     $clipboard = \Session::getInstance()->get('CLIPBOARD');
     $isClipboard = !empty($clipboard[$this->definition->getName()]);
     // Paste buttons
     if ($isClipboard) {
         $clipboard = $clipboard[$this->definition->getName()];
         if (\Input::get('mode') == 'cut' && $this->isChildOf($row, $clipboard['id'])) {
             return \Image::getHtml('pasteafter_.gif', $this->translator->translate('pasteafter.0', $this->definition->getName()));
         }
         $url = \Backend::addToUrl('act=' . $clipboard['mode'] . '&mode=1&pid=' . $row['id'] . '&id=' . $clipboard['id']);
         return sprintf(' <a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a>', $url, specialchars(sprintf($this->translator->translate('pasteafter.1', $this->definition->getName()), $row['id'])), \Image::getHtml('pasteafter.gif', $this->translator->translate('pasteafter.0', $this->definition->getName())));
     }
     return '';
 }
 /**
  * Save new state in database.
  *
  * @param Definition $definition Data container definition.
  * @param int        $recordId   Data record id.
  * @param array      $data       Change data set.
  *
  * @return void
  */
 private function save(Definition $definition, $recordId, array $data)
 {
     // Filter empty values which should not be saved.
     foreach ($data as $column => $value) {
         if ($value != '') {
             continue;
         }
         $alwaysSave = $definition->get(['fields', $column, 'eval', 'alwaysSave'], false);
         $doNotSaveEmpty = $definition->get(['fields', $column, 'eval', 'doNotSaveEmpty'], false);
         if (!$alwaysSave && $doNotSaveEmpty) {
             unset($data[$column]);
         }
     }
     // Add tstamp if field exists.
     if (empty($data['tstamp'] && $this->database->fieldExists('tstamp', $definition->getName()))) {
         $data['tstamp'] = time();
     }
     // Store the data.
     $this->database->prepare(sprintf('UPDATE %s %s WHERE id=?', $definition->getName(), '%s'))->set($data)->execute($recordId);
 }
 /**
  * Format field options.
  *
  * @param string $field   Field name.
  * @param array  $values  Field values.
  * @param mixed  $context Data container object.
  *
  * @return array
  */
 public function formatOptions($field, array $values, $context = null)
 {
     $definition = $this->definition->get(['fields', $field]);
     return $this->optionsFormatter->format($values, $field, $definition, $context);
 }