Exemplo n.º 1
0
 public function preset($id)
 {
     // Validate only exists for JSON.
     if (empty($this->params['ajax'])) {
         $this->undefined();
     }
     $preset = LayoutObject::preset($id);
     if (!$preset) {
         throw new \RuntimeException('Preset not found', 404);
     }
     $layout = new LayoutObject($id, $preset);
     $input = $this->request->post->getJson('layout');
     $deleted = isset($input) ? $layout->clearSections()->copySections($input) : [];
     $message = $deleted ? $this->container['admin.theme']->render('@gantry-admin/ajax/particles-loss.html.twig', ['particles' => $deleted]) : null;
     return new JsonResponse(['title' => ucwords(trim(str_replace('_', ' ', $id))), 'preset' => json_encode($layout->preset), 'data' => $layout->prepareWidths()->toJson(), 'deleted' => $deleted, 'message' => $message]);
 }
Exemplo n.º 2
0
 /**
  * @param string $title
  * @param string $preset
  * @return string
  * @throws \RuntimeException
  */
 public function create($title = 'Untitled', $preset = 'default')
 {
     $gantry = $this->container;
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $name = strtolower(preg_replace('|[^a-z\\d_-]|ui', '_', $title));
     if (!$name) {
         throw new \RuntimeException("Outline needs a name", 400);
     }
     if ($name === 'default' || $name[0] === '_') {
         throw new \RuntimeException("Outline cannot use reserved name '{$name}'", 400);
     }
     $name = $this->findFreeName($name);
     // Create index file for the new layout.
     $layout = new Layout($name, Layout::preset($preset));
     $layout->saveIndex();
     return $name;
 }
Exemplo n.º 3
0
 public function preset($id)
 {
     // Validate only exists for JSON.
     if (empty($this->params['ajax'])) {
         $this->undefined();
     }
     $layout = LayoutObject::preset($id);
     if (!$layout) {
         throw new \RuntimeException('Preset not found', 404);
     }
     $layout = new LayoutObject($id, $layout);
     $deleted = isset($_POST['layout']) ? $layout->clearSections()->copySections(json_decode($_POST['layout'])) : [];
     $message = $deleted ? sprintf('Warning: Following sections could not be found from the new layout: %s.', implode(', ', $deleted)) : null;
     return new JsonResponse(['title' => ucwords(trim(str_replace('_', ' ', $id))), 'preset' => json_encode($layout->preset), 'data' => $layout->toJson(), 'deleted' => $deleted, 'message' => $message]);
 }
Exemplo n.º 4
0
 /**
  * @param string $title
  * @param string $preset
  * @return string
  * @throws \RuntimeException
  */
 public function create($title = 'Untitled', $preset = 'default')
 {
     $name = strtolower(preg_replace('|[^a-z\\d_-]|ui', '_', $title));
     if (!$name) {
         throw new \RuntimeException("Outline needs a name", 400);
     }
     if ($name === 'default' || $name[0] === '_') {
         throw new \RuntimeException("Outline cannot use reserved name '{$name}'", 400);
     }
     $name = $this->findFreeName($name);
     // Load preset.
     $preset = Layout::preset($preset);
     // Create index file for the new layout.
     $layout = new Layout($name, $preset);
     $layout->saveIndex();
     return $name;
 }
Exemplo n.º 5
0
 public function preset($id)
 {
     // Validate only exists for JSON.
     if (empty($this->params['ajax'])) {
         $this->undefined();
     }
     $preset = LayoutObject::preset($id);
     if (!$preset) {
         throw new \RuntimeException('Preset not found', 404);
     }
     return new JsonResponse(['title' => ucwords(trim(str_replace('_', ' ', $id))), 'preset' => json_encode($preset['preset']), 'data' => $preset]);
 }