/** * Constructor * * @param \Cake\ORM\Table $table The table this behavior is attached to. * @param array $config The config for this behavior. */ public function __construct(Table $table, array $config = []) { $config += ['defaultLocale' => I18n::defaultLocale(), 'referenceName' => $this->_referenceName($table)]; if (isset($config['tableLocator'])) { $this->_tableLocator = $config['tableLocator']; } parent::__construct($table, $config); }
/** * Edit a category. * * @return \Cake\Network\Response|void */ public function edit() { $this->loadModel('BlogCategories'); $this->BlogCategories->locale(I18n::defaultLocale()); $category = $this->BlogCategories->find('slug', ['slug' => $this->request->slug, 'slugField' => 'BlogCategories.slug'])->find('translations')->first(); //Check if the category is found. if (empty($category)) { $this->Flash->error(__d('admin', 'This category doesn\'t exist or has been deleted.')); return $this->redirect(['action' => 'index']); } if ($this->request->is('put')) { $this->BlogCategories->patchEntity($category, $this->request->data()); $category->setTranslations($this->request->data); if ($this->BlogCategories->save($category)) { $this->Flash->success(__d('admin', 'This category has been updated successfully !')); return $this->redirect(['action' => 'index']); } } $this->set(compact('category')); }
/** * Edit a Group. * * @return \Cake\Network\Response|void */ public function edit() { $this->Groups->locale(I18n::defaultLocale()); $group = $this->Groups->find('translations')->where(['Groups.id' => $this->request->id])->first(); //Check if the group is found. if (empty($group)) { $this->Flash->error(__d('admin', 'This group doesn\'t exist or has been deleted.')); return $this->redirect(['action' => 'index']); } if ($this->request->is('put')) { $this->Groups->patchEntity($group, $this->request->data()); $group->setTranslations($this->request->data); if ($this->Groups->save($group)) { //Event. $this->eventManager()->attach(new Statistics()); $stats = new Event('Model.Groups.update', $this); $this->eventManager()->dispatch($stats); $this->Flash->success(__d('admin', 'This group has been updated successfully !')); return $this->redirect(['action' => 'index']); } } $this->set(compact('group')); }
/** * Edit an Article. * * @return \Cake\Network\Response|void */ public function edit() { $this->loadModel('BlogArticles'); $this->BlogArticles->locale(I18n::defaultLocale()); $article = $this->BlogArticles->find('translations')->where(['BlogArticles.slug' => $this->request->slug])->contain(['BlogAttachments', 'BlogCategories', 'Users' => function ($q) { return $q->find('short'); }])->first(); //Check if the article is found. if (empty($article)) { $this->Flash->error(__d('admin', 'This article doesn\'t exist or has been deleted.')); return $this->redirect(['action' => 'index']); } if ($this->request->is('put')) { $this->BlogArticles->patchEntity($article, $this->request->data()); $article->setTranslations($this->request->data); if ($this->BlogArticles->save($article)) { $this->Flash->success(__d('admin', 'This article has been updated successfully !')); return $this->redirect(['action' => 'index']); } } $categories = $this->BlogArticles->BlogCategories->find('list'); $this->set(compact('article', 'categories')); }
/** * tearDown * * @return void */ public function tearDown() { parent::tearDown(); I18n::locale(I18n::defaultLocale()); unset($this->controller); }
/** * Constructor * * @param \Cake\ORM\Table $table The table this behavior is attached to. * @param array $config The config for this behavior. */ public function __construct(Table $table, array $config = []) { $config += ['defaultLocale' => I18n::defaultLocale(), 'referenceName' => $this->_referenceName($table)]; parent::__construct($table, $config); }
public function tearDown() { parent::tearDown(); I18n::locale(I18n::defaultLocale()); TableRegistry::clear(); }
/** * Constructor * * @param \Cake\ORM\Table $table The table this behavior is attached to. * @param array $config The config for this behavior. */ public function __construct(Table $table, array $config = []) { $config += ['defaultLocale' => I18n::defaultLocale()]; parent::__construct($table, $config); }
/** * Generate the script tag to initialize CkEditor for textarea. * * @param array $options The options passed to the function. * * @return string */ public function i18nScript($options = []) { $html = ''; $file = isset($options['file']) ? $options['file'] : 'article'; $name = isset($options['name']) ? $options['name'] : 'CkEditorBox'; $i = 0; foreach ($this->_locales as $locale => $lang) { if ($locale == I18n::defaultLocale()) { continue; } $i++; $html .= ' <script type="text/javascript"> CKEDITOR.replace(\'' . $name . '-' . $i . '\', { customConfig: \'config/' . $file . '.js\' }); </script>'; } return $html; }