Esempio n. 1
0
 /**
  * Before render callback.
  *
  * @param \Cake\Event\Event $event The beforeRender event.
  * @return void
  */
 public function beforeRender(Event $event)
 {
     parent::beforeRender($event);
     $params = $this->request->params;
     $page_id = Inflector::dasherize(implode('-', array_merge([$params['controller']], $params['pass'])));
     $this->set(compact('page_id'));
 }
 /**
  * Renders new file input field with value. Applicable for edit action.
  *
  * @param  Table $table Table
  * @param  string $field Field
  * @param  array $options Options
  * @param  mixed $data Data
  * @return string HTML input field with data attribute.
  */
 protected function _renderInputWithData($table, $field, $data, $options)
 {
     $files = [];
     $hiddenIds = '';
     $fieldName = $this->_getFieldName($table, $field);
     $fileUploadsUtils = new FileUploadsUtils($table);
     $entities = $fileUploadsUtils->getFiles($table, $field, $data);
     if ($entities instanceof \Cake\ORM\ResultSet) {
         if (!$entities->count()) {
             return $this->_renderInputWithoutData($table, $field, $options);
         }
     }
     // @TODO: check if we return null anywhere, apart of ResultSet.
     // IF NOT: remove this block
     if (is_null($entities)) {
         return $this->_renderInputWithoutData($table, $field, $options);
     }
     foreach ($entities as $file) {
         $files[] = ['id' => $file->id, 'path' => $file->path];
         $hiddenIds .= $this->cakeView->Form->hidden($this->_getFieldName($table, $field, $options) . '_ids][', ['class' => str_replace('.', '_', $fieldName . '_ids'), 'value' => $file->id]);
     }
     $label = $this->cakeView->Form->label($field);
     $uploadField = $this->cakeView->Form->file($fieldName . '[]', ['multiple' => true, 'data-document-id' => $data, 'data-upload-url' => sprintf("/api/%s/upload", Inflector::dasherize($table->table())), 'data-files' => json_encode($files)]);
     return sprintf(self::WRAPPER, $label, $uploadField, $hiddenIds);
 }
Esempio n. 3
0
 public function bodyCssClass()
 {
     $page = WasabiCms::page();
     $classes = [];
     $classes[] = 'layout-' . Inflector::dasherize($page->layout);
     $classes[] = 'page-' . Inflector::dasherize($page->slug);
     return implode(' ', $classes);
 }
 /**
  * Helper method for dasherizing keys in a URL array.
  *
  * @param array $url An array of URL keys.
  * @return array
  */
 protected function _dasherize($url)
 {
     foreach (['controller', 'plugin', 'action'] as $element) {
         if (!empty($url[$element])) {
             $url[$element] = Inflector::dasherize($url[$element]);
         }
     }
     return $url;
 }
 /**
  * nameTransaction() method.
  *
  * Name the transaction using request data.
  *
  * @param Cake\Network\Network $request The request.
  * @return string
  */
 public function nameTransaction(Request $request)
 {
     $plugin = $request->params['plugin'];
     $prefix = $request->params['prefix'];
     $controller = $request->params['controller'];
     $action = $request->params['action'];
     $transaction = Inflector::dasherize($controller) . '/' . $action;
     if ($prefix !== null) {
         $transaction = Inflector::dasherize($prefix) . '/' . $transaction;
     }
     if ($plugin !== null) {
         $transaction = Inflector::dasherize($plugin) . '/' . $transaction;
     }
     return $transaction;
 }
 /**
  * Generate all files for a plugin
  *
  * Find the first path which contains `src/Template/Bake/Plugin` that contains
  * something, and use that as the template to recursively render a plugin's
  * contents. Allows the creation of a bake them containing a `Plugin` folder
  * to provide customized bake output for plugins.
  *
  * @param string $pluginName the CamelCase name of the plugin
  * @param string $path the path to the plugins dir (the containing folder)
  * @return void
  */
 protected function _generateFiles($pluginName, $path)
 {
     $namespace = str_replace('/', '\\', $pluginName);
     $name = $pluginName;
     $vendor = 'your-name-here';
     if (strpos($pluginName, '/') !== false) {
         list($vendor, $name) = explode('/', $pluginName);
     }
     $package = $vendor . '/' . $name;
     $this->BakeTemplate->set(['package' => $package, 'namespace' => $namespace, 'plugin' => $pluginName, 'routePath' => Inflector::dasherize($pluginName), 'path' => $path, 'root' => ROOT]);
     $root = $path . $pluginName . DS;
     $paths = [];
     if (!empty($this->params['theme'])) {
         $paths[] = Plugin::path($this->params['theme']) . 'src/Template/';
     }
     $paths = array_merge($paths, Configure::read('App.paths.templates'));
     $paths[] = Plugin::path('Bake') . 'src/Template/';
     do {
         $templatesPath = array_shift($paths) . 'Bake/Plugin';
         $templatesDir = new Folder($templatesPath);
         $templates = $templatesDir->findRecursive('.*\\.ctp');
     } while (!$templates);
     sort($templates);
     foreach ($templates as $template) {
         $template = substr($template, strrpos($template, 'Plugin') + 7, -4);
         $this->_generateFile($template, $root);
     }
 }
Esempio n. 7
0
 /**
  * testDasherized method
  *
  * @return void
  */
 public function testDasherized()
 {
     $this->assertSame('test-thing', Inflector::dasherize('TestThing'));
     $this->assertSame('test-thing', Inflector::dasherize('testThing'));
     $this->assertSame('test-thing-extra', Inflector::dasherize('TestThingExtra'));
     $this->assertSame('test-thing-extra', Inflector::dasherize('testThingExtra'));
     $this->assertSame('test-this-thing', Inflector::dasherize('test_this_thing'));
     // Test stupid values
     $this->assertSame('', Inflector::dasherize(null));
     $this->assertSame('', Inflector::dasherize(''));
     $this->assertSame('0', Inflector::dasherize(0));
     $this->assertSame('', Inflector::dasherize(false));
 }
 /**
  * @return void
  */
 private function __setPhoneKeys()
 {
     $keys = [];
     foreach ($this->_fieldsName['phone'] as $key) {
         $inflectored = [Inflector::camelize($key), Inflector::dasherize($key), Inflector::underscore($key), Inflector::variable($key)];
         foreach ($inflectored as $field) {
             // Default Version
             $keys[$field] = $field;
             // strtolower
             $keys[strtolower($key)] = strtolower($key);
             // strtoupper
             $keys[strtoupper($key)] = strtoupper($key);
         }
     }
     $this->_fields['phone'] = $keys;
 }
Esempio n. 9
0
 /**
  * Get the prefix for a namespace.
  *
  * @param string|null $namespace The namespace to get a prefix from.
  * @return string|null
  */
 protected function _getPrefix($namespace = null)
 {
     if (empty($namespace)) {
         return null;
     }
     $pathArray = explode('\\', $namespace);
     if (count($pathArray) >= 5 && $pathArray[3] !== 'Controller') {
         return Inflector::dasherize($pathArray[3]) . '_';
     }
     return null;
 }
Esempio n. 10
0
 /**
  * Before render callback.
  *
  * @param \Cake\Event\Event $event The beforeRender event.
  * @return void
  */
 public function beforeRender(Event $event)
 {
     if (!array_key_exists('_serialize', $this->viewVars) && in_array($this->response->type(), ['application/json', 'application/xml'])) {
         $this->set('_serialize', true);
     }
     $viewVars = [];
     $params = $this->request->params;
     if ($params['controller'] !== 'Pages') {
         $page_id = Inflector::dasherize($params['controller'] . '-' . $params['action']);
         $viewVars[] = 'page_id';
     }
     if ($user = $this->Auth->user()) {
         $user = TableRegistry::get('Users')->get($user['id']);
         $viewVars[] = 'user';
     }
     $this->set(compact($viewVars));
 }
Esempio n. 11
0
 /**
  * Return resource key.
  *
  * @param string $name Name.
  * @return string
  */
 public function resourceKey($name)
 {
     return Inflector::pluralize(Inflector::dasherize($name));
 }