/** * Extract data from request and prepares for inserting a new comment for * the given entity. * * @param \Cake\Datasource\EntityInterface $entity Entity used to guess table name * @return array */ protected function _getRequestData(EntityInterface $entity) { $pk = (string) TableRegistry::get($entity->source())->primaryKey(); $data = $this->_controller->request->data('comment'); $return = ['parent_id' => null, 'subject' => '', 'body' => '', 'status' => 'pending', 'author_name' => null, 'author_email' => null, 'author_web' => null, 'author_ip' => $this->_controller->request->clientIp(), 'table_alias' => $this->_getTableAlias($entity), 'entity_id' => $entity->get($pk)]; if (!empty($this->_controller->request->data['comment'])) { $data = $this->_controller->request->data['comment']; } if ($this->_controller->request->is('userLoggedIn')) { $return['user_id'] = user()->id; $return['author_name'] = null; $return['author_email'] = null; $return['author_web'] = null; } else { $return['author_name'] = !empty($data['author_name']) ? h($data['author_name']) : null; $return['author_email'] = !empty($data['author_email']) ? h($data['author_email']) : null; $return['author_web'] = !empty($data['author_web']) ? h($data['author_web']) : null; } if (!empty($data['subject'])) { $return['subject'] = h($data['subject']); } if (!empty($data['parent_id'])) { // this is validated at Model side $return['parent_id'] = $data['parent_id']; } if (!empty($data['body'])) { $return['body'] = TextToolbox::process($data['body'], $this->config('settings.text_processing')); } if ($this->config('settings.auto_approve') || $this->_controller->request->is('userAdmin')) { $return['status'] = 'approved'; } return $return; }
/** * {@inheritDoc} */ public function render(Field $field, View $view) { $value = TextToolbox::process($field->value, $field->metadata->settings['text_processing']); $field->set('value', $value); return $view->element('Field.TextField/display', compact('field')); }