From 8585c88a21791b4784c4e1295ba824c95b7e91a3 Mon Sep 17 00:00:00 2001 From: Lubos Remplik Date: Fri, 12 Aug 2016 17:43:47 +0200 Subject: [PATCH 1/4] Add options param for createRelationLink; Using buttons instead of simple links with related elements --- .../Element/view/related/has_many.ctp | 15 ++++++--------- src/Template/Element/view/related/has_one.ctp | 19 ++++++++----------- src/View/Helper/CrudViewHelper.php | 6 ++++-- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/Template/Element/view/related/has_many.ctp b/src/Template/Element/view/related/has_many.ctp index 1700a664..669233ea 100644 --- a/src/Template/Element/view/related/has_many.ctp +++ b/src/Template/Element/view/related/has_many.ctp @@ -16,6 +16,9 @@ foreach ($relations as $alias => $details): ?> diff --git a/src/Template/Element/view/related/has_one.ctp b/src/Template/Element/view/related/has_one.ctp index b0a0d148..d2c96427 100644 --- a/src/Template/Element/view/related/has_one.ctp +++ b/src/Template/Element/view/related/has_one.ctp @@ -11,6 +11,14 @@ foreach ($associations['oneToOne'] as $alias => $details): Html->link( __d('crud', 'Add {0}', [Inflector::singularize(Inflector::humanize(Inflector::underscore($alias)))]), @@ -327,7 +328,8 @@ public function createRelationLink($alias, $relation) $relation['foreignKey'] => $this->getViewVar('primaryKeyValue'), '_redirect_url' => $this->request->here ] - ] + ], + $options ); } From d460b607ff859f4ddf3fc3ed3e0429732848b1b3 Mon Sep 17 00:00:00 2001 From: Lubos Remplik Date: Fri, 12 Aug 2016 18:43:07 +0200 Subject: [PATCH 2/4] Fixing typo --- src/View/Helper/CrudViewHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/View/Helper/CrudViewHelper.php b/src/View/Helper/CrudViewHelper.php index 1f388d6c..cc6ea425 100644 --- a/src/View/Helper/CrudViewHelper.php +++ b/src/View/Helper/CrudViewHelper.php @@ -139,7 +139,7 @@ public function introspect($field, $value, array $options = []) $value = $this->formatString($field, $value); if ($field === $this->getViewVar('displayField')) { - return $this->formatdisplayField($value, $options); + return $this->formatDisplayField($value, $options); } return $value; From 3dc6ad928fd2bb40dbb243f7aa66c06c4140251f Mon Sep 17 00:00:00 2001 From: Lubos Remplik Date: Fri, 12 Aug 2016 18:53:23 +0200 Subject: [PATCH 3/4] Fixing code sniffer errors --- src/Listener/ViewListener.php | 18 ++++++++++++++++++ src/Listener/ViewSearchListener.php | 2 ++ src/View/CrudView.php | 14 +++++++++++++- src/View/Helper/CrudViewHelper.php | 8 ++++++++ src/View/Widget/DateTimeWidget.php | 4 ++++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/Listener/ViewListener.php b/src/Listener/ViewListener.php index 9a325570..73ec350b 100644 --- a/src/Listener/ViewListener.php +++ b/src/Listener/ViewListener.php @@ -443,6 +443,8 @@ protected function _normalizeActions($actions) $normalized[$config] = []; } } + + return $normalized; } @@ -553,6 +555,8 @@ protected function _deriveFieldFromContext($field) protected function _getViewBlocks() { $action = $this->_action(); + + return $action->config('scaffold.viewblocks') ?: []; } @@ -564,6 +568,8 @@ protected function _getViewBlocks() protected function _getBulkActions() { $action = $this->_action(); + + return $action->config('scaffold.bulk_actions') ?: []; } @@ -575,6 +581,8 @@ protected function _getBulkActions() protected function _getFormUrl() { $action = $this->_action(); + + return $action->config('scaffold.form_action') ?: null; } @@ -586,6 +594,8 @@ protected function _getFormUrl() protected function _getDisableExtraButtons() { $action = $this->_action(); + + return $action->config('scaffold.disable_extra_buttons') ?: false; } @@ -597,6 +607,8 @@ protected function _getDisableExtraButtons() protected function _getDisableSidebar() { $action = $this->_action(); + + return $action->config('scaffold.disable_sidebar') ?: false; } @@ -608,6 +620,8 @@ protected function _getDisableSidebar() protected function _getExtraButtonsBlacklist() { $action = $this->_action(); + + return $action->config('scaffold.extra_buttons_blacklist') ?: []; } @@ -619,6 +633,8 @@ protected function _getExtraButtonsBlacklist() protected function _getEnableDirtyCheck() { $action = $this->_action(); + + return $action->config('scaffold.enable_dirty_check') ?: false; } @@ -636,6 +652,8 @@ protected function _getActionGroups() // add "primary" actions (primary should rendered as separate buttons) $groups['primary'] = array_diff(array_keys($this->_getAllowedActions()), $groupedActions); + + return $groups; } } diff --git a/src/Listener/ViewSearchListener.php b/src/Listener/ViewSearchListener.php index 02747cb1..318928bd 100644 --- a/src/Listener/ViewSearchListener.php +++ b/src/Listener/ViewSearchListener.php @@ -141,6 +141,8 @@ protected function _deriveFields() $fields[$field] = $input; } + + return $fields; } } diff --git a/src/View/CrudView.php b/src/View/CrudView.php index a3f7fb8f..ffbe86d6 100644 --- a/src/View/CrudView.php +++ b/src/View/CrudView.php @@ -56,6 +56,8 @@ protected function _loadAssets() $this->AssetCompress->css('CrudView.crudview', ['block' => true]); $this->AssetCompress->script('CrudView.crudview_head', ['block' => 'headjs']); $this->AssetCompress->script('CrudView.crudview', ['block' => true]); + + return; } @@ -136,6 +138,8 @@ public function fetch($name, $default = '') } $internal = $this->Blocks->get($name, $default); + + return $internal . $viewblock; } @@ -149,13 +153,17 @@ public function fetch($name, $default = '') public function exists($name) { $viewblocks = $this->get('viewblocks', []); + + return !empty($viewblocks[$name]) || $this->Blocks->exists($name); } /** * Constructs a ViewBlock from an array of configured data * - * @return void + * @param array $data ViewBlock data + * + * @return string */ protected function _createViewblock($data) { @@ -171,6 +179,8 @@ protected function _createViewblock($data) $output .= $key; } } + + return $output; } @@ -191,6 +201,8 @@ protected function _getViewFileName($name = null) } catch (MissingTemplateException $exception) { $this->subDir = null; $this->templatePath = 'Scaffold'; + + return parent::_getViewFileName($this->template); } } diff --git a/src/View/Helper/CrudViewHelper.php b/src/View/Helper/CrudViewHelper.php index cc6ea425..a3cce720 100644 --- a/src/View/Helper/CrudViewHelper.php +++ b/src/View/Helper/CrudViewHelper.php @@ -68,6 +68,8 @@ public function process($field, Entity $data, array $options = []) if ($options['formatter'] === 'element') { $context = $this->getContext(); + + return $this->_View->element($options['element'], compact('context', 'field', 'value', 'options')); } @@ -189,6 +191,8 @@ public function formatDate($field, $value, array $options) if ($value === null) { return $this->Html->label(__d('crud', 'N/A'), 'info'); } + + return $this->Time->timeAgoInWords($value, $options); } @@ -206,6 +210,8 @@ public function formatTime($field, $value, array $options) return $this->Html->label(__d('crud', 'N/A'), 'info'); } $format = isset($options['format']) ? $options['format'] : null; + + return $this->Time->nice($value, $format); } @@ -262,6 +268,8 @@ public function relation($field) } $entity = $data->$entityName; + + return [ 'alias' => $alias, 'output' => $this->Html->link($entity->{$details['displayField']}, [ diff --git a/src/View/Widget/DateTimeWidget.php b/src/View/Widget/DateTimeWidget.php index e414b862..2b8c496a 100644 --- a/src/View/Widget/DateTimeWidget.php +++ b/src/View/Widget/DateTimeWidget.php @@ -81,6 +81,8 @@ class="form-control" html; + + return $widget; } @@ -132,6 +134,8 @@ protected function _convertPHPToMomentFormat($format) 'U' => 'X', ]; $momentFormat = strtr($format, $replacements); + + return $momentFormat; } } From dc0a4343812a0d3ee528c49eaac9d9c41b07bce1 Mon Sep 17 00:00:00 2001 From: Lubos Remplik Date: Sat, 13 Aug 2016 11:08:57 +0200 Subject: [PATCH 4/4] Fix for double line before return, deleting 4 spaces lines --- src/Listener/ViewListener.php | 9 --------- src/Listener/ViewSearchListener.php | 1 - src/View/CrudView.php | 5 ----- src/View/Helper/CrudViewHelper.php | 4 ---- src/View/Widget/DateTimeWidget.php | 2 -- 5 files changed, 21 deletions(-) diff --git a/src/Listener/ViewListener.php b/src/Listener/ViewListener.php index 73ec350b..4ca419f2 100644 --- a/src/Listener/ViewListener.php +++ b/src/Listener/ViewListener.php @@ -443,7 +443,6 @@ protected function _normalizeActions($actions) $normalized[$config] = []; } } - return $normalized; } @@ -555,7 +554,6 @@ protected function _deriveFieldFromContext($field) protected function _getViewBlocks() { $action = $this->_action(); - return $action->config('scaffold.viewblocks') ?: []; } @@ -568,7 +566,6 @@ protected function _getViewBlocks() protected function _getBulkActions() { $action = $this->_action(); - return $action->config('scaffold.bulk_actions') ?: []; } @@ -581,7 +578,6 @@ protected function _getBulkActions() protected function _getFormUrl() { $action = $this->_action(); - return $action->config('scaffold.form_action') ?: null; } @@ -594,7 +590,6 @@ protected function _getFormUrl() protected function _getDisableExtraButtons() { $action = $this->_action(); - return $action->config('scaffold.disable_extra_buttons') ?: false; } @@ -607,7 +602,6 @@ protected function _getDisableExtraButtons() protected function _getDisableSidebar() { $action = $this->_action(); - return $action->config('scaffold.disable_sidebar') ?: false; } @@ -620,7 +614,6 @@ protected function _getDisableSidebar() protected function _getExtraButtonsBlacklist() { $action = $this->_action(); - return $action->config('scaffold.extra_buttons_blacklist') ?: []; } @@ -633,7 +626,6 @@ protected function _getExtraButtonsBlacklist() protected function _getEnableDirtyCheck() { $action = $this->_action(); - return $action->config('scaffold.enable_dirty_check') ?: false; } @@ -652,7 +644,6 @@ protected function _getActionGroups() // add "primary" actions (primary should rendered as separate buttons) $groups['primary'] = array_diff(array_keys($this->_getAllowedActions()), $groupedActions); - return $groups; } diff --git a/src/Listener/ViewSearchListener.php b/src/Listener/ViewSearchListener.php index 318928bd..1270594c 100644 --- a/src/Listener/ViewSearchListener.php +++ b/src/Listener/ViewSearchListener.php @@ -141,7 +141,6 @@ protected function _deriveFields() $fields[$field] = $input; } - return $fields; } diff --git a/src/View/CrudView.php b/src/View/CrudView.php index ffbe86d6..ad4c1a5c 100644 --- a/src/View/CrudView.php +++ b/src/View/CrudView.php @@ -56,7 +56,6 @@ protected function _loadAssets() $this->AssetCompress->css('CrudView.crudview', ['block' => true]); $this->AssetCompress->script('CrudView.crudview_head', ['block' => 'headjs']); $this->AssetCompress->script('CrudView.crudview', ['block' => true]); - return; } @@ -138,7 +137,6 @@ public function fetch($name, $default = '') } $internal = $this->Blocks->get($name, $default); - return $internal . $viewblock; } @@ -153,7 +151,6 @@ public function fetch($name, $default = '') public function exists($name) { $viewblocks = $this->get('viewblocks', []); - return !empty($viewblocks[$name]) || $this->Blocks->exists($name); } @@ -179,7 +176,6 @@ protected function _createViewblock($data) $output .= $key; } } - return $output; } @@ -201,7 +197,6 @@ protected function _getViewFileName($name = null) } catch (MissingTemplateException $exception) { $this->subDir = null; $this->templatePath = 'Scaffold'; - return parent::_getViewFileName($this->template); } diff --git a/src/View/Helper/CrudViewHelper.php b/src/View/Helper/CrudViewHelper.php index a3cce720..f6cf2618 100644 --- a/src/View/Helper/CrudViewHelper.php +++ b/src/View/Helper/CrudViewHelper.php @@ -68,7 +68,6 @@ public function process($field, Entity $data, array $options = []) if ($options['formatter'] === 'element') { $context = $this->getContext(); - return $this->_View->element($options['element'], compact('context', 'field', 'value', 'options')); } @@ -191,7 +190,6 @@ public function formatDate($field, $value, array $options) if ($value === null) { return $this->Html->label(__d('crud', 'N/A'), 'info'); } - return $this->Time->timeAgoInWords($value, $options); } @@ -210,7 +208,6 @@ public function formatTime($field, $value, array $options) return $this->Html->label(__d('crud', 'N/A'), 'info'); } $format = isset($options['format']) ? $options['format'] : null; - return $this->Time->nice($value, $format); } @@ -268,7 +265,6 @@ public function relation($field) } $entity = $data->$entityName; - return [ 'alias' => $alias, diff --git a/src/View/Widget/DateTimeWidget.php b/src/View/Widget/DateTimeWidget.php index 2b8c496a..ad927d42 100644 --- a/src/View/Widget/DateTimeWidget.php +++ b/src/View/Widget/DateTimeWidget.php @@ -81,7 +81,6 @@ class="form-control" html; - return $widget; } @@ -134,7 +133,6 @@ protected function _convertPHPToMomentFormat($format) 'U' => 'X', ]; $momentFormat = strtr($format, $replacements); - return $momentFormat; }