diff --git a/.travis.yml b/.travis.yml index a2d66def..316a2eb3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,9 @@ language: php php: - - 7 + - 5.6 + - 7.0 + - 7.1 before_script: - composer self-update diff --git a/composer.json b/composer.json index 0314dc1f..0a079d93 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ } ], "require": { - "cakephp/cakephp": "~3.0", + "cakephp/cakephp": "~3.4", "friendsofcake/crud": "*", "friendsofcake/bootstrap-ui": "~1.2" }, diff --git a/docs/_partials/pages/index/download-format-links.rst b/docs/_partials/pages/index/download-format-links.rst index 4325b435..eba4d217 100644 --- a/docs/_partials/pages/index/download-format-links.rst +++ b/docs/_partials/pages/index/download-format-links.rst @@ -20,11 +20,11 @@ Each sub-array should contain ``title`` and ``url`` parameters. $action->config('scaffold.index_formats', [ [ 'title' => 'JSON', - 'url' => ['_ext' => 'json', '?' => $this->request->query] + 'url' => ['_ext' => 'json', '?' => $this->request->getQueryParams()] ], [ 'title' => 'XML', - 'url' => Router::url(['_ext' => 'xml', '?' => $this->request->query]) + 'url' => Router::url(['_ext' => 'xml', '?' => $this->request->getQueryParams()]) ], ]); @@ -86,7 +86,7 @@ can be modified to add a CSV Download Link. $this->Crud->action()->config('scaffold.index_formats', [ [ 'title' => 'CSV', - 'url' => ['_ext' => 'csv', '?' => $this->request->query] + 'url' => ['_ext' => 'csv', '?' => $this->request->getQueryParams()] ], ]); return $this->Crud->execute(); diff --git a/docs/_partials/pages/index/finder-scopes.rst b/docs/_partials/pages/index/finder-scopes.rst index 450f9d8f..05c9f87b 100644 --- a/docs/_partials/pages/index/finder-scopes.rst +++ b/docs/_partials/pages/index/finder-scopes.rst @@ -70,8 +70,8 @@ result-set. This can be done in the mapped action as follows: ]); // We don't need to check for `all` as it is the default findMethod - if (in_array($this->request->query('finder'), ['active', 'inactive'])) { - $this->Crud->action()->config('findMethod', $this->request->query('finder')); + if (in_array($this->request->getQuery('finder'), ['active', 'inactive'])) { + $this->Crud->action()->config('findMethod', $this->request->getQuery('finder')); } return $this->Crud->execute(); } diff --git a/docs/basic-usage.rst b/docs/basic-usage.rst index 3f03f4cc..e3cb8b1f 100644 --- a/docs/basic-usage.rst +++ b/docs/basic-usage.rst @@ -101,7 +101,7 @@ alter the ``contain()`` list for the pagination query: public function index() { $this->Crud->on('beforePaginate', function ($event) { - $paginationQuery = $event->subject()->query; + $paginationQuery = $event->getSubject()->query; $paginationQuery->contain([ 'Categories', 'Authors' => ['fields' => ['id', 'name']] @@ -306,9 +306,9 @@ you can use the ``relatedModels`` event: public function add() { $this->Crud->on('relatedModel', function(\Cake\Event\Event $event) { - if ($event->subject->association->name() === 'Categories') { - $event->subject->query->limit(3); - $event->subject->query->where(['is_active' => true]); + if ($event->getSubject()->association->name() === 'Categories') { + $event->getSubject()->query->limit(3); + $event->getSubject()->query->where(['is_active' => true]); } }); return $this->Crud->execute(); @@ -483,7 +483,7 @@ alter the ``contain()`` list for the pagination query: public function view() { $this->Crud->on('beforeFind', function ($event) { - $event->subject()->query->contain([ + $event->getSubject()->query->contain([ 'Categories', 'Authors' => ['fields' => ['id', 'name']] ]); diff --git a/src/Listener/Traits/FormTypeTrait.php b/src/Listener/Traits/FormTypeTrait.php index 4cf36c20..37013539 100644 --- a/src/Listener/Traits/FormTypeTrait.php +++ b/src/Listener/Traits/FormTypeTrait.php @@ -1,17 +1,14 @@ _controller(); @@ -38,9 +35,9 @@ protected function _getFormEnableDirtyCheck() { $action = $this->_action(); - $formEnableDirtyCheck = $action->config('scaffold.form_enable_dirty_check'); + $formEnableDirtyCheck = $action->getConfig('scaffold.form_enable_dirty_check'); if ($formEnableDirtyCheck === null) { - $formEnableDirtyCheck = $action->config('scaffold.enable_dirty_check'); + $formEnableDirtyCheck = $action->getConfig('scaffold.enable_dirty_check'); if ($formEnableDirtyCheck !== null) { $this->deprecatedScaffoldKeyNotice( 'scaffold.enable_dirty_check', @@ -61,9 +58,9 @@ protected function _getFormSubmitButtonText() { $action = $this->_action(); - $formSubmitButtonText = $action->config('scaffold.form_submit_button_text'); + $formSubmitButtonText = $action->getConfig('scaffold.form_submit_button_text'); if ($formSubmitButtonText === null) { - $formSubmitButtonText = $action->config('scaffold.submit_button_text'); + $formSubmitButtonText = $action->getConfig('scaffold.submit_button_text'); if ($formSubmitButtonText !== null) { $this->deprecatedScaffoldKeyNotice( 'scaffold.submit_button_text', @@ -132,7 +129,7 @@ protected function _getFormSubmitExtraButtons() $defaults = $newDefaults; } - $buttons = $action->config('scaffold.form_submit_extra_buttons'); + $buttons = $action->getConfig('scaffold.form_submit_extra_buttons'); if ($buttons === null || $buttons === true) { $buttons = $defaults; } @@ -154,7 +151,7 @@ protected function _getFormDisableExtraButtons() { $action = $this->_action(); - return $action->config('scaffold.disable_extra_buttons') ?: false; + return $action->getConfig('scaffold.disable_extra_buttons') ?: false; } /** @@ -167,7 +164,7 @@ protected function _getFormExtraButtonsBlacklist() { $action = $this->_action(); - return $action->config('scaffold.extra_buttons_blacklist') ?: []; + return $action->getConfig('scaffold.extra_buttons_blacklist') ?: []; } /** @@ -179,7 +176,7 @@ protected function _getFormUrl() { $action = $this->_action(); - return $action->config('scaffold.form_action') ?: null; + return $action->getConfig('scaffold.form_action') ?: null; } /** diff --git a/src/Listener/Traits/IndexTypeTrait.php b/src/Listener/Traits/IndexTypeTrait.php index 10231527..bcbddf3b 100644 --- a/src/Listener/Traits/IndexTypeTrait.php +++ b/src/Listener/Traits/IndexTypeTrait.php @@ -1,17 +1,14 @@ _getIndexTitleField(); $indexBodyField = $this->_getIndexBodyField(); @@ -39,7 +36,7 @@ protected function _getIndexFinderScopes() { $action = $this->_action(); - return $action->config('scaffold.index_finder_scopes') ?: []; + return $action->getConfig('scaffold.index_finder_scopes') ?: []; } /** @@ -52,7 +49,7 @@ protected function _getIndexFormats() { $action = $this->_action(); - return $action->config('scaffold.index_formats') ?: []; + return $action->getConfig('scaffold.index_formats') ?: []; } /** @@ -64,7 +61,7 @@ protected function _getIndexType() { $action = $this->_action(); - $indexType = $action->config('scaffold.index_type'); + $indexType = $action->getConfig('scaffold.index_type'); if (empty($indexType)) { $indexType = 'table'; } @@ -81,9 +78,9 @@ protected function _getIndexTitleField() { $action = $this->_action(); - $field = $action->config('scaffold.index_title_field'); + $field = $action->getConfig('scaffold.index_title_field'); if ($field === null) { - $field = $action->config('scaffold.index_blog_title_field'); + $field = $action->getConfig('scaffold.index_blog_title_field'); if ($field !== null) { $this->deprecatedScaffoldKeyNotice( 'scaffold.index_blog_title_field', @@ -93,7 +90,7 @@ protected function _getIndexTitleField() } if (empty($field)) { - $field = $this->_table()->displayField(); + $field = $this->_table()->getDisplayField(); } return $field; @@ -108,9 +105,9 @@ protected function _getIndexBodyField() { $action = $this->_action(); - $field = $action->config('scaffold.index_body_field'); + $field = $action->getConfig('scaffold.index_body_field'); if ($field === null) { - $field = $action->config('scaffold.index_blog_body_field'); + $field = $action->getConfig('scaffold.index_blog_body_field'); if ($field !== null) { $this->deprecatedScaffoldKeyNotice( 'scaffold.index_blog_body_field', @@ -135,7 +132,7 @@ protected function _getIndexImageField() { $action = $this->_action(); - $field = $action->config('scaffold.index_image_field'); + $field = $action->getConfig('scaffold.index_image_field'); if (empty($field)) { $field = 'image'; } @@ -152,7 +149,7 @@ protected function _getIndexGalleryCssClasses() { $action = $this->_action(); - $field = $action->config('scaffold.index_gallery_css_classes'); + $field = $action->getConfig('scaffold.index_gallery_css_classes'); if (empty($field)) { $field = 'col-sm-6 col-md-3'; } diff --git a/src/Listener/Traits/SidebarNavigationTrait.php b/src/Listener/Traits/SidebarNavigationTrait.php index 1a79bbfc..37d7d554 100644 --- a/src/Listener/Traits/SidebarNavigationTrait.php +++ b/src/Listener/Traits/SidebarNavigationTrait.php @@ -1,17 +1,14 @@ _controller(); $sidebarNavigation = $this->_getSidebarNavigation(); @@ -29,11 +26,11 @@ protected function _getSidebarNavigation() $action = $this->_action(); // deprecated check - if ($action->config('scaffold.disable_sidebar')) { + if ($action->getConfig('scaffold.disable_sidebar')) { return false; } - return $action->config('scaffold.sidebar_navigation'); + return $action->getConfig('scaffold.sidebar_navigation'); } /** diff --git a/src/Listener/Traits/SiteTitleTrait.php b/src/Listener/Traits/SiteTitleTrait.php index 6a0de25c..637a388d 100644 --- a/src/Listener/Traits/SiteTitleTrait.php +++ b/src/Listener/Traits/SiteTitleTrait.php @@ -2,17 +2,15 @@ namespace CrudView\Listener\Traits; use Cake\Core\Configure; -use Cake\Event\Event; trait SiteTitleTrait { /** * beforeRender event * - * @param \Cake\Event\Event $event Event. * @return void */ - public function beforeRenderSiteTitle(Event $event) + public function beforeRenderSiteTitle() { $controller = $this->_controller(); @@ -34,7 +32,7 @@ protected function _getSiteTitle() { $action = $this->_action(); - $title = $action->config('scaffold.site_title'); + $title = $action->getConfig('scaffold.site_title'); if (!empty($title)) { return $title; } @@ -45,7 +43,7 @@ protected function _getSiteTitle() } // deprecated - $title = $action->config('scaffold.brand'); + $title = $action->getConfig('scaffold.brand'); if (!empty($title)) { return $title; } @@ -62,7 +60,7 @@ protected function _getSiteTitleLink() { $action = $this->_action(); - $link = $action->config('scaffold.site_title_link'); + $link = $action->getConfig('scaffold.site_title_link'); if (empty($link)) { $link = ''; } @@ -79,7 +77,7 @@ protected function _getSiteTitleImage() { $action = $this->_action(); - $image = $action->config('scaffold.site_title_image'); + $image = $action->getConfig('scaffold.site_title_image'); if (empty($image)) { $image = ''; } diff --git a/src/Listener/Traits/UtilityNavigationTrait.php b/src/Listener/Traits/UtilityNavigationTrait.php index c81ff035..81a5958c 100644 --- a/src/Listener/Traits/UtilityNavigationTrait.php +++ b/src/Listener/Traits/UtilityNavigationTrait.php @@ -1,7 +1,6 @@ _controller(); $controller->set('utilityNavigation', $this->_getUtilityNavigation()); @@ -27,7 +25,7 @@ protected function _getUtilityNavigation() { $action = $this->_action(); - $utilityNavigation = $action->config('scaffold.utility_navigation'); + $utilityNavigation = $action->getConfig('scaffold.utility_navigation'); if ($utilityNavigation === null) { $utilityNavigation = [ new MenuItem('Account', ['controller' => 'Users', 'action' => 'account']), diff --git a/src/Listener/ViewListener.php b/src/Listener/ViewListener.php index cf5d878e..e5709a80 100644 --- a/src/Listener/ViewListener.php +++ b/src/Listener/ViewListener.php @@ -41,8 +41,8 @@ class ViewListener extends BaseListener public function beforeFind(Event $event) { $this->associations = $this->_associations(array_keys($this->_getRelatedModels())); - if (!$event->subject()->query->contain()) { - $event->subject()->query->contain($this->_getRelatedModels()); + if (!$event->getSubject()->query->contain()) { + $event->getSubject()->query->contain($this->_getRelatedModels()); } } @@ -55,8 +55,8 @@ public function beforeFind(Event $event) public function beforePaginate(Event $event) { $this->associations = $this->_associations(array_keys($this->_getRelatedModels())); - if (!$event->subject()->query->contain()) { - $event->subject()->query->contain($this->_getRelatedModels(['manyToOne', 'oneToOne'])); + if (!$event->getSubject()->query->contain()) { + $event->getSubject()->query->contain($this->_getRelatedModels(['manyToOne', 'oneToOne'])); } } @@ -72,8 +72,8 @@ public function beforeRender(Event $event) return; } - if (!empty($event->subject()->entity)) { - $this->_entity = $event->subject()->entity; + if (!empty($event->getSubject()->entity)) { + $this->_entity = $event->getSubject()->entity; } if (empty($this->associations)) { @@ -82,13 +82,13 @@ public function beforeRender(Event $event) $this->ensureConfig(); - $this->beforeRenderFormType($event); - $this->beforeRenderIndexType($event); - $this->beforeRenderSiteTitle($event); - $this->beforeRenderUtilityNavigation($event); - $this->beforeRenderSidebarNavigation($event); + $this->beforeRenderFormType(); + $this->beforeRenderIndexType(); + $this->beforeRenderSiteTitle(); + $this->beforeRenderUtilityNavigation(); + $this->beforeRenderSidebarNavigation(); $controller = $this->_controller(); - $controller->set('actionConfig', $this->_action()->config()); + $controller->set('actionConfig', $this->_action()->getConfig()); $controller->set('title', $this->_getPageTitle()); $controller->set('breadcrumbs', $this->_getBreadcrumbs()); $associations = $this->associations; @@ -127,8 +127,8 @@ public function ensureConfig() */ public function setFlash(Event $event) { - unset($event->subject()->params['class']); - $event->subject()->element = ltrim($event->subject()->type); + unset($event->getSubject()->params['class']); + $event->getSubject()->element = ltrim($event->getSubject()->type); } /** @@ -140,12 +140,12 @@ protected function _getPageTitle() { $action = $this->_action(); - $title = $action->config('scaffold.page_title'); + $title = $action->getConfig('scaffold.page_title'); if (!empty($title)) { return $title; } - $scope = $action->config('scope'); + $scope = $action->getConfig('scope'); $request = $this->_request(); $actionName = Inflector::humanize(Inflector::underscore($request->action)); @@ -165,7 +165,7 @@ protected function _getPageTitle() } $displayFieldValue = $this->_displayFieldValue(); - if ($displayFieldValue === null || $this->_table()->displayField() == $this->_table()->primaryKey()) { + if ($displayFieldValue === null || $this->_table()->getDisplayField() == $this->_table()->getPrimaryKey()) { return sprintf('%s %s #%s', $actionName, $controllerName, $primaryKeyValue); } @@ -181,7 +181,7 @@ protected function _getBreadcrumbs() { $action = $this->_action(); - return $action->config('scaffold.breadcrumbs') ?: []; + return $action->getConfig('scaffold.breadcrumbs') ?: []; } /** @@ -198,7 +198,7 @@ protected function _getBreadcrumbs() */ protected function _getRelatedModels($relations = []) { - $models = $this->_action()->config('scaffold.relations'); + $models = $this->_action()->getConfig('scaffold.relations'); if ($models === false) { return []; @@ -219,7 +219,7 @@ protected function _getRelatedModels($relations = []) $models = Hash::normalize($models); - $blacklist = $this->_action()->config('scaffold.relations_blacklist'); + $blacklist = $this->_action()->getConfig('scaffold.relations_blacklist'); if (!empty($blacklist)) { $blacklist = Hash::normalize($blacklist); $models = array_diff_key($models, $blacklist); @@ -241,7 +241,7 @@ protected function _getRelatedModels($relations = []) */ protected function _blacklist() { - return (array)$this->_action()->config('scaffold.fields_blacklist'); + return (array)$this->_action()->getConfig('scaffold.fields_blacklist'); } /** @@ -253,17 +253,17 @@ protected function _getPageVariables() { $table = $this->_table(); $controller = $this->_controller(); - $scope = $this->_action()->config('scope'); + $scope = $this->_action()->getConfig('scope'); $data = [ 'modelClass' => $controller->modelClass, - 'modelSchema' => $table->schema(), - 'displayField' => $table->displayField(), + 'modelSchema' => $table->getSchema(), + 'displayField' => $table->getDisplayField(), 'singularHumanName' => Inflector::humanize(Inflector::underscore(Inflector::singularize($controller->modelClass))), 'pluralHumanName' => Inflector::humanize(Inflector::underscore($controller->name)), 'singularVar' => Inflector::singularize($controller->name), 'pluralVar' => Inflector::variable($controller->name), - 'primaryKey' => $table->primaryKey(), + 'primaryKey' => $table->getPrimaryKey(), ]; if ($scope === 'entity') { @@ -284,16 +284,16 @@ protected function _getPageVariables() protected function _scaffoldFields(array $associations = []) { $action = $this->_action(); - $scaffoldFields = (array)$action->config('scaffold.fields'); + $scaffoldFields = (array)$action->getConfig('scaffold.fields'); if (!empty($scaffoldFields)) { $scaffoldFields = Hash::normalize($scaffoldFields); } - if (empty($scaffoldFields) || $action->config('scaffold.autoFields')) { - $cols = $this->_table()->schema()->columns(); + if (empty($scaffoldFields) || $action->getConfig('scaffold.autoFields')) { + $cols = $this->_table()->getSchema()->columns(); $cols = Hash::normalize($cols); - $scope = $action->config('scope'); + $scope = $action->getConfig('scope'); if ($scope === 'entity' && !empty($associations['manyToMany'])) { foreach ($associations['manyToMany'] as $alias => $options) { $cols[sprintf('%s._ids', $options['entities'])] = [ @@ -306,7 +306,7 @@ protected function _scaffoldFields(array $associations = []) } // Check for blacklisted fields - $blacklist = $action->config('scaffold.fields_blacklist'); + $blacklist = $action->getConfig('scaffold.fields_blacklist'); if (!empty($blacklist)) { $scaffoldFields = array_diff_key($scaffoldFields, array_combine($blacklist, $blacklist)); } @@ -320,7 +320,7 @@ protected function _scaffoldFields(array $associations = []) $scaffoldFields[$field] += ['formatter' => null]; } - $fieldSettings = $action->config('scaffold.field_settings'); + $fieldSettings = $action->getConfig('scaffold.field_settings'); if (empty($fieldSettings)) { $fieldSettings = []; } @@ -371,7 +371,7 @@ protected function _getControllerActions() } $actionBlacklist = []; - $groups = $this->_action()->config('scaffold.action_groups') ?: []; + $groups = $this->_action()->getConfig('scaffold.action_groups') ?: []; foreach ($groups as $group) { $group = Hash::normalize($group); foreach ($group as $actionName => $config) { @@ -454,19 +454,19 @@ protected function _getControllerActionConfiguration($actionName, $config) */ protected function _getAllowedActions() { - $actions = $this->_action()->config('scaffold.actions'); + $actions = $this->_action()->getConfig('scaffold.actions'); if ($actions === null) { - $actions = $this->_crud()->config('actions'); + $actions = $this->_crud()->getConfig('actions'); } - $extraActions = $this->_action()->config('scaffold.extra_actions') ?: []; + $extraActions = $this->_action()->getConfig('scaffold.extra_actions') ?: []; $allActions = array_merge( $this->_normalizeActions($actions), $this->_normalizeActions($extraActions) ); - $blacklist = (array)$this->_action()->config('scaffold.actions_blacklist'); + $blacklist = (array)$this->_action()->getConfig('scaffold.actions_blacklist'); $blacklist = array_combine($blacklist, $blacklist); return array_diff_key($allActions, $blacklist); @@ -513,7 +513,7 @@ protected function _associations(array $whitelist = []) $associations = $table->associations(); $keys = $associations->keys(); - if ($whitelist) { + if (!empty($whitelist)) { $keys = array_intersect($keys, array_map('strtolower', $whitelist)); } foreach ($keys as $associationName) { @@ -527,8 +527,8 @@ protected function _associations(array $whitelist = []) $assocKey = $association->name(); $associationConfiguration[$type][$assocKey]['model'] = $assocKey; $associationConfiguration[$type][$assocKey]['type'] = $type; - $associationConfiguration[$type][$assocKey]['primaryKey'] = $association->target()->primaryKey(); - $associationConfiguration[$type][$assocKey]['displayField'] = $association->target()->displayField(); + $associationConfiguration[$type][$assocKey]['primaryKey'] = $association->target()->getPrimaryKey(); + $associationConfiguration[$type][$assocKey]['displayField'] = $association->target()->getDisplayField(); $associationConfiguration[$type][$assocKey]['foreignKey'] = $association->foreignKey(); $associationConfiguration[$type][$assocKey]['propertyName'] = $association->property(); $associationConfiguration[$type][$assocKey]['plugin'] = pluginSplit($association->className())[0]; @@ -536,7 +536,7 @@ protected function _associations(array $whitelist = []) $associationConfiguration[$type][$assocKey]['entity'] = Inflector::singularize(Inflector::underscore($assocKey)); $associationConfiguration[$type][$assocKey]['entities'] = Inflector::underscore($assocKey); - $associationConfiguration[$type][$assocKey] = array_merge($associationConfiguration[$type][$assocKey], $this->_action()->config('association.' . $assocKey) ?: []); + $associationConfiguration[$type][$assocKey] = array_merge($associationConfiguration[$type][$assocKey], $this->_action()->getConfig('association.' . $assocKey) ?: []); } return $associationConfiguration; @@ -551,7 +551,7 @@ protected function _associations(array $whitelist = []) */ protected function _primaryKeyValue() { - return $this->_deriveFieldFromContext($this->_table()->primaryKey()); + return $this->_deriveFieldFromContext($this->_table()->getPrimaryKey()); } /** @@ -563,11 +563,11 @@ protected function _primaryKeyValue() */ protected function _displayFieldValue() { - return $this->_deriveFieldFromContext($this->_table()->displayField()); + return $this->_deriveFieldFromContext($this->_table()->getDisplayField()); } /** - * Extract a field value from a either the CakeRequest::$data + * Extract a field value from a either the CakeRequest::getData() * or Controller::$viewVars for the current model + the supplied field * * @param string $field Name of field. @@ -585,8 +585,8 @@ protected function _deriveFieldFromContext($field) } $path = "{$controller->modelClass}.{$field}"; - if (!empty($request->data)) { - $value = Hash::get((array)$request->data, $path); + if (!empty($request->getData())) { + $value = Hash::get((array)$request->getData(), $path); } $singularVar = Inflector::variable($controller->modelClass); @@ -606,7 +606,7 @@ protected function _getViewBlocks() { $action = $this->_action(); - return $action->config('scaffold.viewblocks') ?: []; + return $action->getConfig('scaffold.viewblocks') ?: []; } /** @@ -618,7 +618,7 @@ protected function _getBulkActions() { $action = $this->_action(); - return $action->config('scaffold.bulk_actions') ?: []; + return $action->getConfig('scaffold.bulk_actions') ?: []; } /** @@ -629,7 +629,7 @@ protected function _getBulkActions() protected function _getActionGroups() { $action = $this->_action(); - $groups = $action->config('scaffold.action_groups') ?: []; + $groups = $action->getConfig('scaffold.action_groups') ?: []; $groupedActions = []; foreach ($groups as $group) { diff --git a/src/Listener/ViewSearchListener.php b/src/Listener/ViewSearchListener.php index 9974c3d6..9ff48a36 100644 --- a/src/Listener/ViewSearchListener.php +++ b/src/Listener/ViewSearchListener.php @@ -43,11 +43,12 @@ public function implementedEvents() */ public function afterPaginate(Event $event) { + $event; if (!$this->_table()->behaviors()->has('Search')) { return; } - $enabled = $this->config('enabled') ?: !$this->_request()->is('api'); + $enabled = $this->getConfig('enabled') ?: !$this->_request()->is('api'); if (!$enabled) { return; } @@ -63,7 +64,7 @@ public function afterPaginate(Event $event) */ public function fields() { - return $this->config('fields') ?: $this->_deriveFields(); + return $this->getConfig('fields') ?: $this->_deriveFields(); } /** @@ -83,11 +84,11 @@ protected function _deriveFields() } $fields = []; - $schema = $table->schema(); + $schema = $table->getSchema(); $config = $this->_config; foreach ($filters->all() as $filter) { - if ($filter->config('form') === false) { + if ($filter->getConfig('form') === false) { continue; } @@ -105,7 +106,7 @@ protected function _deriveFields() 'type' => 'text' ]; - $input['value'] = $request->query($field); + $input['value'] = $request->getQuery($field); if (empty($input['options']) && $schema->columnType($field) === 'boolean') { $input['options'] = ['No', 'Yes']; @@ -130,8 +131,10 @@ protected function _deriveFields() $urlArgs = []; $fieldKeys = isset($input['fields']) ? $input['fields'] : ['id' => $field, 'value' => $field]; - foreach ($fieldKeys as $key => $val) { - $urlArgs[$key] = $val; + if (is_array($fieldKeys)) { + foreach ($fieldKeys as $key => $val) { + $urlArgs[$key] = $val; + } } unset($input['fields']); diff --git a/src/View/Helper/CrudViewHelper.php b/src/View/Helper/CrudViewHelper.php index 05436613..df460c44 100644 --- a/src/View/Helper/CrudViewHelper.php +++ b/src/View/Helper/CrudViewHelper.php @@ -7,6 +7,7 @@ use Cake\Utility\Text; use Cake\View\Helper; use Cake\View\Helper\FormHelper; +use DateTime; /** * @property \Cake\View\Helper\FormHelper $Form @@ -162,7 +163,7 @@ public function columnType($field) * Format a boolean value for display * * @param string $field Name of field. - * @param array $value Value of field. + * @param mixed $value Value of field. * @param array $options Options array * @return string */ @@ -177,7 +178,7 @@ public function formatBoolean($field, $value, $options) * Format a date for display * * @param string $field Name of field. - * @param array $value Value of field. + * @param mixed $value Value of field. * @param array $options Options array. * @return string */ @@ -187,14 +188,18 @@ public function formatDate($field, $value, array $options) return $this->Html->label(__d('crud', 'N/A'), 'info'); } - return $this->Time->timeAgoInWords($value, $options); + if (is_int($value) || is_string($value) || $value instanceof DateTime) { + return $this->Time->timeAgoInWords($value, $options); + } + + return $this->Html->label(__d('crud', 'N/A'), 'info'); } /** * Format a time for display * * @param string $field Name of field. - * @param array $value Value of field. + * @param mixed $value Value of field. * @param array $options Options array. * @return string */ @@ -205,26 +210,30 @@ public function formatTime($field, $value, array $options) } $format = isset($options['format']) ? $options['format'] : null; - return $this->Time->nice($value, $format); + if (is_int($value) || is_string($value) || $value instanceof DateTime) { + return $this->Time->nice($value, $format); + } + + return $this->Html->label(__d('crud', 'N/A'), 'info'); } /** * Format a string for display * * @param string $field Name of field. - * @param array $value Value of field. + * @param mixed $value Value of field. * @return string */ public function formatString($field, $value) { - return h(Text::truncate($value, 200)); + return h(Text::truncate((string)$value, 200)); } /** * Format display field value. * * @param string $value Display field value. - * @param array $options Field options. + * @param mixed $options Field options. * @return string */ public function formatDisplayField($value, array $options) @@ -284,7 +293,7 @@ public function relation($field) */ public function redirectUrl() { - $redirectUrl = $this->request->query('_redirect_url'); + $redirectUrl = $this->request->getQuery('_redirect_url'); $redirectUrlViewVar = $this->getViewVar('_redirect_url'); if (!empty($redirectUrlViewVar)) { @@ -326,7 +335,7 @@ public function createRelationLink($alias, $relation, $options = []) 'action' => 'add', '?' => [ $relation['foreignKey'] => $this->getViewVar('primaryKeyValue'), - '_redirect_url' => $this->request->here + '_redirect_url' => $this->request->getUri()->getPath() ] ], $options @@ -407,7 +416,7 @@ public function getViewVar($key = null) */ public function getCssClasses() { - $action = (string)$this->request->param('action'); + $action = (string)$this->request->getParam('action'); $pluralVar = $this->getViewVar('pluralVar'); $viewClasses = (array)$this->getViewVar('viewClasses'); $args = func_get_args();