Example #1
0
 /**
  * Updates a menu item to have at least a 'link' key.
  *
  * @param array $item
  *
  * @return array Keys 'link' and possibly 'label', 'title' and 'path'
  */
 private function menuHelper($item)
 {
     // recurse into submenu's
     if (isset($item['submenu']) && is_array($item['submenu'])) {
         $item['submenu'] = $this->menuHelper($item['submenu']);
     }
     if (isset($item['route'])) {
         $param = !empty($item['param']) ? $item['param'] : [];
         $add = !empty($item['add']) ? $item['add'] : '';
         $item['link'] = $this->app->generatePath($item['route'], $param, $add);
     } elseif (isset($item['path'])) {
         $item = $this->resolvePathToContent($item);
     }
     return $item;
 }
Example #2
0
 /**
  * Return the URI for a package's config file edit window.
  *
  * @param string $name
  *
  * @return string
  */
 private function linkConfig($name)
 {
     // Generate the configfilename from the extension $name
     $configfilename = join('.', array_reverse(explode('/', $name))) . '.yml';
     // Check if we have a config file, and if it's readable. (yet)
     $configfilepath = $this->app['resources']->getPath('extensionsconfig/' . $configfilename);
     if (is_readable($configfilepath)) {
         return $this->app->generatePath('fileedit', ['namespace' => 'config', 'file' => 'extensions/' . $configfilename]);
     }
     return null;
 }
Example #3
0
 /**
  * Sanity checks for doubles in in contenttypes.
  */
 public function checkConfig()
 {
     $slugs = [];
     $wrongctype = false;
     foreach ($this->data['contenttypes'] as $key => $ct) {
         /**
          * Make sure any field that has a 'uses' parameter actually points to a field that exists.
          *
          * For example, this will show a notice:
          * entries:
          *   name: Entries
          *     singular_name: Entry
          *     fields:
          *       title:
          *         type: text
          *         class: large
          *       slug:
          *         type: slug
          *         uses: name
          */
         foreach ($ct['fields'] as $fieldname => $field) {
             // Verify that the contenttype doesn't try to add fields that are reserved.
             if ($fieldname != 'slug' && in_array($fieldname, $this->reservedFieldNames)) {
                 $error = Trans::__('contenttypes.generic.reserved-name', ['%contenttype%' => $key, '%field%' => $fieldname]);
                 $this->app['logger.flash']->error($error);
                 return;
             }
             // Check 'uses'. If it's an array, split it up, and check the separate parts. We also need to check
             // for the fields that are always present, like 'id'.
             if (is_array($field) && !empty($field['uses'])) {
                 foreach ($field['uses'] as $useField) {
                     if (!empty($field['uses']) && empty($ct['fields'][$useField]) && !in_array($useField, $this->reservedFieldNames)) {
                         $error = Trans::__('contenttypes.generic.wrong-use-field', ['%contenttype%' => $key, '%field%' => $fieldname, '%uses%' => $useField]);
                         $this->app['logger.flash']->error($error);
                         return;
                     }
                 }
             }
             // Make sure the 'type' is in the list of allowed types
             if (!isset($field['type']) || !$this->fields->has($field['type'])) {
                 $error = Trans::__('contenttypes.generic.no-proper-type', ['%contenttype%' => $key, '%field%' => $fieldname, '%type%' => $field['type']]);
                 $this->app['logger.flash']->error($error);
                 $wrongctype = true && $this->app['users']->getCurrentUsername();
             }
         }
         // Keep a running score of used slugs.
         if (!isset($slugs[$ct['slug']])) {
             $slugs[$ct['slug']] = 0;
         }
         $slugs[$ct['slug']]++;
         if (!isset($slugs[$ct['singular_slug']])) {
             $slugs[$ct['singular_slug']] = 0;
         }
         if ($ct['singular_slug'] != $ct['slug']) {
             $slugs[$ct['singular_slug']]++;
         }
     }
     // Check DB-tables integrity
     if (!$wrongctype && $this->app['schema']->needsCheck() && $this->app['schema']->needsUpdate() && $this->app['users']->getCurrentUsername()) {
         $msg = Trans::__("The database needs to be updated/repaired. Go to 'Configuration' > '<a href=\"%link%\">Check Database</a>' to do this now.", ['%link%' => $this->app->generatePath('dbcheck')]);
         $this->app['logger.flash']->error($msg);
         return;
     }
     // Sanity checks for taxonomy.yml
     foreach ($this->data['taxonomy'] as $key => $taxo) {
         // Show some helpful warnings if slugs or keys are not set correctly.
         if ($taxo['slug'] != $key) {
             $error = Trans::__("The identifier and slug for '%taxonomytype%' are the not the same ('%slug%' vs. '%taxonomytype%'). Please edit taxonomy.yml, and make them match to prevent inconsistencies between database storage and your templates.", ['%taxonomytype%' => $key, '%slug%' => $taxo['slug']]);
             $this->app['logger.flash']->error($error);
             return;
         }
     }
     // if there aren't any other errors, check for duplicates across contenttypes.
     if (!$this->app['logger.flash']->has('error')) {
         foreach ($slugs as $slug => $count) {
             if ($count > 1) {
                 $error = Trans::__("The slug '%slug%' is used in more than one contenttype. Please edit contenttypes.yml, and make them distinct.", ['%slug%' => $slug]);
                 $this->app['logger.flash']->error($error);
                 return;
             }
         }
     }
 }