예제 #1
0
 /**
  * Generate the list buttons.
  *
  * @param array $row The data row.
  *
  * @return string
  */
 private function generateListOperations($row)
 {
     $dca = $this->definition->get('list/operations');
     $return = '';
     foreach ($dca as $name => $button) {
         // Cut mode would create empty child list. Disable so far.
         if ($name === 'cut') {
             continue;
         }
         $button = is_array($button) ? $button : array($button);
         $id = specialchars(rawurldecode($row['id']));
         $label = $button['label'][0] ?: $name;
         $title = sprintf($button['label'][1] ?: $name, $id);
         $attributes = $button['attributes'] != '' ? ' ' . ltrim(sprintf($button['attributes'], $id, $id)) : '';
         // Add the key as CSS class
         if (strpos($attributes, 'class="') !== false) {
             $attributes = str_replace('class="', 'class="' . $name . ' ', $attributes);
         } else {
             $attributes = ' class="' . $name . '"' . $attributes;
         }
         // Call a custom function instead of using the default button
         if ($button['button_callback']) {
             $return .= $this->callButtonCallback($button, $row, $label, $title, $attributes);
             continue;
         }
         if ($name == 'show') {
             $attributes .= sprintf(' onclick="Backend.openModalIframe({\'width\':768,\'title\':\'%s\',\'url\':this.href});return false"', specialchars(str_replace("'", "\\'", $this->translator->translate('show', $this->definition->getName(), array($row['id'])))));
         }
         $return .= sprintf('<a href="%s" title="%s" %s>%s</a> ', \Backend::addToUrl($button['href'] . '&amp;nodes=1&amp;id=' . $row['id'] . ($name == 'show' ? '&amp;popup=1' : '')), specialchars($title), $attributes, \Image::getHtml($button['icon'], $label));
     }
     return $return;
 }
예제 #2
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);
     }
 }
예제 #4
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 '';
 }
 /**
  * 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);
 }