Skip to content

Commit

Permalink
Merge pull request #192 from FriendsOfCake/remove-deprecated-code
Browse files Browse the repository at this point in the history
Remove deprecated code
  • Loading branch information
josegonzalez authored Jun 28, 2017
2 parents 8723c8c + b54aea6 commit a0f8ce4
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 195 deletions.
1 change: 0 additions & 1 deletion config/defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

return [
'CrudView' => [
'brand' => 'Crud View',
'siteTitle' => 'Crud View',
'css' => [
'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.css',
Expand Down
24 changes: 3 additions & 21 deletions docs/basic-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -356,36 +356,18 @@ Disabling the Extra Submit Buttons
----------------------------------

You may have noticed already that in the ``add`` form there are multiple submit
buttons. If you wish to only keep the "Save" button, you set the ``scaffold.disable_extra_buttons``
configuration key to ``true``:
buttons. If you wish to only keep the "Save" button, you set the
``scaffold.form_submit_extra_buttons`` configuration key to ``false``:

.. code-block:: php
public function add()
{
$action = $this->Crud->action();
$action->config('scaffold.disable_extra_buttons', true);
$action->config('scaffold.form_submit_extra_buttons', false);
return $this->Crud->execute();
}
It is also possible to only disable a few of the extra submit buttons by using
the ``scaffold.extra_buttons_blacklist`` configuration key:

.. code-block:: php
public function add()
{
$action = $this->Crud->action();
$action->config('scaffold.extra_buttons_blacklist', [
'save_and_continue', // Hide the Save and Continue button
'save_and_create', // Hide the Save and create new button
'back', // Hide the back button
]);
return $this->Crud->execute();
}
Both settings can be used in ``add`` and ``edit`` actions.

Implementing a View Action
--------------------------

Expand Down
4 changes: 1 addition & 3 deletions docs/general-configuration/site-title-options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ Site Title
----------

You can use the ``scaffold.site_title`` config variable to modify the title. If
not set, it will fallback to the following alternatives:
not set, it will fallback to the following alternative:

- ``Configure::read('CrudView.siteTitle')``
- ``$action->config('scaffold.brand')``: Deprecated
- ``Configure::read('CrudView.brand')``: Deprecated

.. code-block:: php
Expand Down
4 changes: 0 additions & 4 deletions docs/index-pages/components/blog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ The blog index type has two main options:
$action->config('scaffold.index_title_field', 'name');
$action->config('scaffold.index_body_field', 'content');
// the following are deprecated ways of setting the title and body
$action->config('scaffold.index_blog_title_field', 'name');
$action->config('scaffold.index_blog_body_field', 'content');
Available Variables
-------------------

Expand Down
97 changes: 4 additions & 93 deletions src/Listener/Traits/FormTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,10 @@ protected function beforeRenderFormType()
{
$controller = $this->_controller();

$formEnableDirtyCheck = $this->_getFormEnableDirtyCheck();
$formSubmitButtonText = $this->_getFormSubmitButtonText();

$controller->set('formEnableDirtyCheck', $formEnableDirtyCheck);
$controller->set('formSubmitButtonText', $formSubmitButtonText);
$controller->set('formEnableDirtyCheck', $this->_getFormEnableDirtyCheck());
$controller->set('formSubmitButtonText', $this->_getFormSubmitButtonText());
$controller->set('formSubmitExtraButtons', $this->_getFormSubmitExtraButtons());
$controller->set('formUrl', $this->_getFormUrl());

$controller->set('enableDirtyCheck', $formEnableDirtyCheck);
$controller->set('submitButtonText', $formSubmitButtonText);
$controller->set('disableExtraButtons', $this->_getFormDisableExtraButtons());
$controller->set('extraButtonsBlacklist', $this->_getFormExtraButtonsBlacklist());
}

/**
Expand All @@ -35,18 +27,7 @@ protected function _getFormEnableDirtyCheck()
{
$action = $this->_action();

$formEnableDirtyCheck = $action->getConfig('scaffold.form_enable_dirty_check');
if ($formEnableDirtyCheck === null) {
$formEnableDirtyCheck = $action->getConfig('scaffold.enable_dirty_check');
if ($formEnableDirtyCheck !== null) {
$this->deprecatedScaffoldKeyNotice(
'scaffold.enable_dirty_check',
'scaffold.form_enable_dirty_check'
);
}
}

return $formEnableDirtyCheck ?: false;
return $action->getConfig('scaffold.form_enable_dirty_check') ?: false;
}

/**
Expand All @@ -58,18 +39,7 @@ protected function _getFormSubmitButtonText()
{
$action = $this->_action();

$formSubmitButtonText = $action->getConfig('scaffold.form_submit_button_text');
if ($formSubmitButtonText === null) {
$formSubmitButtonText = $action->getConfig('scaffold.submit_button_text');
if ($formSubmitButtonText !== null) {
$this->deprecatedScaffoldKeyNotice(
'scaffold.submit_button_text',
'scaffold.form_submit_button_text'
);
}
}

return $formSubmitButtonText ?: __d('crud', 'Save');
return $action->getConfig('scaffold.form_submit_button_text') ?: __d('crud', 'Save');
}

/**
Expand All @@ -81,16 +51,6 @@ protected function _getFormSubmitExtraButtons()
{
$action = $this->_action();

$disableExtraButtons = $this->_getFormDisableExtraButtons();
if ($disableExtraButtons === true) {
$this->deprecatedScaffoldKeyNotice(
'scaffold.disable_extra_buttons',
'scaffold.form_submit_extra_buttons'
);

return [];
}

$defaults = [
[
'title' => __d('crud', 'Save & continue editing'),
Expand All @@ -113,22 +73,6 @@ protected function _getFormSubmitExtraButtons()
],
];

$extraButtonsBlacklist = $this->_getFormExtraButtonsBlacklist();
if (!empty($extraButtonsBlacklist)) {
$this->deprecatedScaffoldKeyNotice(
'scaffold.extra_buttons_blacklist',
'scaffold.form_submit_extra_buttons'
);
$newDefaults = [];
foreach ($defaults as $default) {
if (in_array($default['_label'], $extraButtonsBlacklist)) {
continue;
}
$newDefaults[] = $default;
}
$defaults = $newDefaults;
}

$buttons = $action->getConfig('scaffold.form_submit_extra_buttons');
if ($buttons === null || $buttons === true) {
$buttons = $defaults;
Expand All @@ -141,32 +85,6 @@ protected function _getFormSubmitExtraButtons()
return $buttons;
}

/**
* Disable extra buttons.
*
* @return bool
* @deprecated 0.7.0 Deprecated in favor of form_submit_extra_buttons
*/
protected function _getFormDisableExtraButtons()
{
$action = $this->_action();

return $action->getConfig('scaffold.disable_extra_buttons') ?: false;
}

/**
* Get extra buttons blacklist
*
* @return array
* @deprecated 0.7.0 Deprecated in favor of form_submit_extra_buttons
*/
protected function _getFormExtraButtonsBlacklist()
{
$action = $this->_action();

return $action->getConfig('scaffold.extra_buttons_blacklist') ?: [];
}

/**
* Get form url.
*
Expand All @@ -188,11 +106,4 @@ abstract protected function _controller();
* {@inheritDoc}
*/
abstract protected function _action($name = null);

/**
* {@inheritDoc}
* @param string $deprecatedKey
* @param string $newKey
*/
abstract protected function deprecatedScaffoldKeyNotice($deprecatedKey, $newKey);
}
37 changes: 2 additions & 35 deletions src/Listener/Traits/IndexTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@ trait IndexTypeTrait
*/
public function beforeRenderIndexType()
{
$indexTitleField = $this->_getIndexTitleField();
$indexBodyField = $this->_getIndexBodyField();

$controller = $this->_controller();
$controller->set('indexFinderScopes', $this->_getIndexFinderScopes());
$controller->set('indexFormats', $this->_getIndexFormats());
$controller->set('indexType', $this->_getIndexType());
$controller->set('indexTitleField', $indexTitleField);
$controller->set('indexBodyField', $indexBodyField);
$controller->set('indexTitleField', $this->_getIndexTitleField());
$controller->set('indexBodyField', $this->_getIndexBodyField());
$controller->set('indexImageField', $this->_getIndexImageField());
$controller->seT('indexGalleryCssClasses', $this->_getIndexGalleryCssClasses());

$controller->set('indexBlogTitleField', $indexTitleField);
$controller->set('indexBlogBodyField', $indexBodyField);
}

/**
Expand Down Expand Up @@ -80,16 +74,6 @@ protected function _getIndexTitleField()

$field = $action->getConfig('scaffold.index_title_field');
if ($field === null) {
$field = $action->getConfig('scaffold.index_blog_title_field');
if ($field !== null) {
$this->deprecatedScaffoldKeyNotice(
'scaffold.index_blog_title_field',
'scaffold.index_title_field'
);
}
}

if (empty($field)) {
$field = $this->_table()->getDisplayField();
}

Expand All @@ -107,16 +91,6 @@ protected function _getIndexBodyField()

$field = $action->getConfig('scaffold.index_body_field');
if ($field === null) {
$field = $action->getConfig('scaffold.index_blog_body_field');
if ($field !== null) {
$this->deprecatedScaffoldKeyNotice(
'scaffold.index_blog_body_field',
'scaffold.index_body_field'
);
}
}

if (empty($field)) {
$field = 'body';
}

Expand Down Expand Up @@ -171,11 +145,4 @@ abstract protected function _action($name = null);
* {@inheritDoc}
*/
abstract protected function _table();

/**
* {@inheritDoc}
* @param string $deprecatedKey
* @param string $newKey
*/
abstract protected function deprecatedScaffoldKeyNotice($deprecatedKey, $newKey);
}
5 changes: 0 additions & 5 deletions src/Listener/Traits/SidebarNavigationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ protected function _getSidebarNavigation()
{
$action = $this->_action();

// deprecated check
if ($action->getConfig('scaffold.disable_sidebar')) {
return false;
}

return $action->getConfig('scaffold.sidebar_navigation');
}

Expand Down
19 changes: 2 additions & 17 deletions src/Listener/Traits/SiteTitleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ public function beforeRenderSiteTitle()
{
$controller = $this->_controller();

$siteTitle = $this->_getSiteTitle();
$controller->set('siteTitle', $siteTitle);
$controller->set('siteTitle', $this->_getSiteTitle());
$controller->set('siteTitleLink', $this->_getSiteTitleLink());
$controller->set('siteTitleImage', $this->_getSiteTitleImage());

// deprecated
$controller->set('brand', $siteTitle);
}

/**
Expand All @@ -37,18 +33,7 @@ protected function _getSiteTitle()
return $title;
}

$title = Configure::read('CrudView.siteTitle');
if (!empty($title)) {
return $title;
}

// deprecated
$title = $action->getConfig('scaffold.brand');
if (!empty($title)) {
return $title;
}

return Configure::read('CrudView.brand');
return Configure::read('CrudView.siteTitle');
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/Listener/ViewListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Cake\Event\Event;
use Cake\Utility\Hash;
use Cake\Utility\Inflector;
use CrudView\Listener\Traits\DeprecatedConfigurationKeyTrait;
use CrudView\Listener\Traits\FormTypeTrait;
use CrudView\Listener\Traits\IndexTypeTrait;
use CrudView\Listener\Traits\SidebarNavigationTrait;
Expand All @@ -18,7 +17,6 @@
class ViewListener extends BaseListener
{
use CrudViewConfigTrait;
use DeprecatedConfigurationKeyTrait;
use FormTypeTrait;
use IndexTypeTrait;
use SidebarNavigationTrait;
Expand Down
14 changes: 0 additions & 14 deletions src/Template/Element/form.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ $formSidebarExists = $this->exists('form.sidebar');
if ($this->exists('form.before_create')) {
echo $this->fetch('form.before_create');
}
if ($this->exists('before_form')) {
$template = 'The view block %s has been deprecated. Use %s instead.';
$message = sprintf($template, 'before_form', 'form.before_create');
trigger_error($message, E_USER_DEPRECATED);

echo $this->fetch('before_form');
}
?>

<div class="<?= $this->CrudView->getCssClasses(); ?>">
Expand Down Expand Up @@ -48,11 +41,4 @@ if ($this->exists('before_form')) {
if ($this->exists('form.after_end')) {
echo $this->fetch('form.after_end');
}
if ($this->exists('after_form')) {
$template = 'The view block %s has been deprecated. Use %s instead.';
$message = sprintf($template, 'after_form', 'form.after_end');
trigger_error($message, E_USER_DEPRECATED);

echo $this->fetch('after_form');
}
?>

0 comments on commit a0f8ce4

Please sign in to comment.