Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
73fbcf80
Commit
73fbcf80
authored
Jun 17, 2013
by
Alex Pott
Browse files
Issue
#2011018
by tim.plunkett: Reconcile entity forms and confirm forms.
parent
025aa2a1
Changes
66
Hide whitespace changes
Inline
Side-by-side
core/lib/Drupal/Core/Entity/EntityConfirmFormBase.php
0 → 100644
View file @
73fbcf80
<?php
/**
* @file
* Contains \Drupal\Core\Entity\EntityConfirmFormBase.
*/
namespace
Drupal\Core\Entity
;
use
Drupal\Core\Form\ConfirmFormInterface
;
use
Symfony\Component\HttpFoundation\Request
;
/**
* Provides a generic base class for an entity-based confirmation form.
*/
abstract
class
EntityConfirmFormBase
extends
EntityFormController
implements
ConfirmFormInterface
{
/**
* The request object.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected
$request
;
/**
* {@inheritdoc}
*/
public
function
getDescription
()
{
return
t
(
'This action cannot be undone.'
);
}
/**
* {@inheritdoc}
*/
public
function
getConfirmText
()
{
return
t
(
'Confirm'
);
}
/**
* {@inheritdoc}
*/
public
function
getCancelText
()
{
return
t
(
'Cancel'
);
}
/**
* {@inheritdoc}
*/
public
function
getFormName
()
{
return
'confirm'
;
}
/**
* {@inheritdoc}
*/
public
function
buildForm
(
array
$form
,
array
&
$form_state
,
Request
$request
=
NULL
)
{
$this
->
request
=
$request
;
$form
=
parent
::
buildForm
(
$form
,
$form_state
);
$form
[
'#attributes'
][
'class'
][]
=
'confirmation'
;
$form
[
'description'
]
=
array
(
'#markup'
=>
$this
->
getDescription
());
$form
[
$this
->
getFormName
()]
=
array
(
'#type'
=>
'hidden'
,
'#value'
=>
1
);
// By default, render the form using theme_confirm_form().
if
(
!
isset
(
$form
[
'#theme'
]))
{
$form
[
'#theme'
]
=
'confirm_form'
;
}
return
$form
;
}
/**
* {@inheritdoc}
*/
protected
function
init
(
array
&
$form_state
)
{
parent
::
init
(
$form_state
);
drupal_set_title
(
$this
->
getQuestion
(),
PASS_THROUGH
);
}
/**
* {@inheritdoc}
*/
protected
function
actions
(
array
$form
,
array
&
$form_state
)
{
$actions
=
parent
::
actions
(
$form
,
$form_state
);
$actions
[
'submit'
][
'#value'
]
=
$this
->
getConfirmText
();
unset
(
$actions
[
'delete'
]);
$path
=
$this
->
getCancelPath
();
// Prepare cancel link.
if
(
$this
->
request
->
query
->
has
(
'destination'
))
{
$options
=
drupal_parse_url
(
$this
->
request
->
query
->
get
(
'destination'
));
}
elseif
(
is_array
(
$path
))
{
$options
=
$path
;
}
else
{
$options
=
array
(
'path'
=>
$path
);
}
$actions
[
'cancel'
]
=
array
(
'#type'
=>
'link'
,
'#title'
=>
$this
->
getCancelText
(),
'#href'
=>
$options
[
'path'
],
'#options'
=>
$options
,
);
return
$actions
;
}
}
core/lib/Drupal/Core/Entity/EntityNGConfirmFormBase.php
0 → 100644
View file @
73fbcf80
<?php
/**
* @file
* Contains \Drupal\Core\Entity\EntityNGConfirmFormBase.
*/
namespace
Drupal\Core\Entity
;
use
Drupal\Core\Form\ConfirmFormInterface
;
use
Symfony\Component\HttpFoundation\Request
;
/**
* Provides a generic base class for an entity-based confirmation form.
*/
abstract
class
EntityNGConfirmFormBase
extends
EntityFormControllerNG
implements
ConfirmFormInterface
{
/**
* The request object.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected
$request
;
/**
* {@inheritdoc}
*/
public
function
getDescription
()
{
return
t
(
'This action cannot be undone.'
);
}
/**
* {@inheritdoc}
*/
public
function
getConfirmText
()
{
return
t
(
'Confirm'
);
}
/**
* {@inheritdoc}
*/
public
function
getCancelText
()
{
return
t
(
'Cancel'
);
}
/**
* {@inheritdoc}
*/
public
function
getFormName
()
{
return
'confirm'
;
}
/**
* {@inheritdoc}
*/
public
function
buildForm
(
array
$form
,
array
&
$form_state
,
Request
$request
=
NULL
)
{
$this
->
request
=
$request
;
$form
=
parent
::
buildForm
(
$form
,
$form_state
);
$form
[
'#attributes'
][
'class'
][]
=
'confirmation'
;
$form
[
'description'
]
=
array
(
'#markup'
=>
$this
->
getDescription
());
$form
[
$this
->
getFormName
()]
=
array
(
'#type'
=>
'hidden'
,
'#value'
=>
1
);
// By default, render the form using theme_confirm_form().
if
(
!
isset
(
$form
[
'#theme'
]))
{
$form
[
'#theme'
]
=
'confirm_form'
;
}
return
$form
;
}
/**
* {@inheritdoc}
*/
protected
function
init
(
array
&
$form_state
)
{
parent
::
init
(
$form_state
);
drupal_set_title
(
$this
->
getQuestion
(),
PASS_THROUGH
);
}
/**
* {@inheritdoc}
*/
protected
function
actions
(
array
$form
,
array
&
$form_state
)
{
$actions
=
parent
::
actions
(
$form
,
$form_state
);
$actions
[
'submit'
][
'#value'
]
=
$this
->
getConfirmText
();
unset
(
$actions
[
'delete'
]);
$path
=
$this
->
getCancelPath
();
// Prepare cancel link.
if
(
$this
->
request
->
query
->
has
(
'destination'
))
{
$options
=
drupal_parse_url
(
$this
->
request
->
query
->
get
(
'destination'
));
}
elseif
(
is_array
(
$path
))
{
$options
=
$path
;
}
else
{
$options
=
array
(
'path'
=>
$path
);
}
$actions
[
'cancel'
]
=
array
(
'#type'
=>
'link'
,
'#title'
=>
$this
->
getCancelText
(),
'#href'
=>
$options
[
'path'
],
'#options'
=>
$options
,
);
return
$actions
;
}
}
core/lib/Drupal/Core/Form/ConfirmFormBase.php
View file @
73fbcf80
...
...
@@ -7,80 +7,49 @@
namespace
Drupal\Core\Form
;
use
Symfony\Component\HttpFoundation\Request
;
/**
* Provides an generic base class for a confirmation form.
*/
abstract
class
ConfirmFormBase
implements
FormInterface
{
/**
* Returns the question to ask the user.
*
* @return string
* The form question. The page title will be set to this value.
*/
abstract
protected
function
getQuestion
();
/**
* Returns the page to go to if the user cancels the action.
*
* @return string|array
* This can be either:
* - A string containing a Drupal path.
* - An associative array with a 'path' key. Additional array values are
* passed as the $options parameter to l().
* If the 'destination' query parameter is set in the URL when viewing a
* confirmation form, that value will be used instead of this path.
*/
abstract
protected
function
getCancelPath
();
abstract
class
ConfirmFormBase
implements
ConfirmFormInterface
{
/**
* Returns additional text to display as a description.
*
* @return string
* The form description.
* {@inheritdoc}
*/
p
rotected
function
getDescription
()
{
p
ublic
function
getDescription
()
{
return
t
(
'This action cannot be undone.'
);
}
/**
* Returns a caption for the button that confirms the action.
*
* @return string
* The form confirmation text.
* {@inheritdoc}
*/
p
rotected
function
getConfirmText
()
{
p
ublic
function
getConfirmText
()
{
return
t
(
'Confirm'
);
}
/**
* Returns a caption for the link which cancels the action.
*
* @return string
* The form cancellation text.
* {@inheritdoc}
*/
p
rotected
function
getCancelText
()
{
p
ublic
function
getCancelText
()
{
return
t
(
'Cancel'
);
}
/**
* Returns the internal name used to refer to the confirmation item.
*
* @return string
* The internal form name.
* {@inheritdoc}
*/
p
rotected
function
getFormName
()
{
p
ublic
function
getFormName
()
{
return
'confirm'
;
}
/**
*
Implements \Drupal\Core\Form\FormInterface::buildForm().
*
{@inheritdoc}
*/
public
function
buildForm
(
array
$form
,
array
&
$form_state
)
{
public
function
buildForm
(
array
$form
,
array
&
$form_state
,
Request
$request
=
NULL
)
{
$path
=
$this
->
getCancelPath
();
// Prepare cancel link.
if
(
isset
(
$_GET
[
'destination'
]
))
{
$options
=
drupal_parse_url
(
$
_GET
[
'destination'
]
);
if
(
$request
->
query
->
has
(
'destination'
))
{
$options
=
drupal_parse_url
(
$
request
->
query
->
get
(
'destination'
)
);
}
elseif
(
is_array
(
$path
))
{
$options
=
$path
;
...
...
@@ -114,7 +83,7 @@ public function buildForm(array $form, array &$form_state) {
}
/**
*
Implements \Drupal\Core\Form\FormInterface::validateForm().
*
{@inheritdoc}
*/
public
function
validateForm
(
array
&
$form
,
array
&
$form_state
)
{
}
...
...
core/lib/Drupal/Core/Form/ConfirmFormInterface.php
0 → 100644
View file @
73fbcf80
<?php
/**
* @file
* Contains \Drupal\Core\Form\ConfirmFormInterface.
*/
namespace
Drupal\Core\Form
;
/**
* Defines the behavior a confirmation form.
*/
interface
ConfirmFormInterface
extends
FormInterface
{
/**
* Returns the question to ask the user.
*
* @return string
* The form question. The page title will be set to this value.
*/
public
function
getQuestion
();
/**
* Returns the page to go to if the user cancels the action.
*
* @return string|array
* This can be either:
* - A string containing a Drupal path.
* - An associative array with a 'path' key. Additional array values are
* passed as the $options parameter to l().
* If the 'destination' query parameter is set in the URL when viewing a
* confirmation form, that value will be used instead of this path.
*/
public
function
getCancelPath
();
/**
* Returns additional text to display as a description.
*
* @return string
* The form description.
*/
public
function
getDescription
();
/**
* Returns a caption for the button that confirms the action.
*
* @return string
* The form confirmation text.
*/
public
function
getConfirmText
();
/**
* Returns a caption for the link which cancels the action.
*
* @return string
* The form cancellation text.
*/
public
function
getCancelText
();
/**
* Returns the internal name used to refer to the confirmation item.
*
* @return string
* The internal form name.
*/
public
function
getFormName
();
}
core/modules/action/action.module
View file @
73fbcf80
...
...
@@ -73,5 +73,6 @@ function action_menu() {
function
action_entity_info
(
&
$entity_info
)
{
$entity_info
[
'action'
][
'controllers'
][
'form'
][
'add'
]
=
'Drupal\action\ActionAddFormController'
;
$entity_info
[
'action'
][
'controllers'
][
'form'
][
'edit'
]
=
'Drupal\action\ActionEditFormController'
;
$entity_info
[
'action'
][
'controllers'
][
'form'
][
'delete'
]
=
'Drupal\action\Form\ActionDeleteForm'
;
$entity_info
[
'action'
][
'controllers'
][
'list'
]
=
'Drupal\action\ActionListController'
;
}
core/modules/action/action.routing.yml
View file @
73fbcf80
...
...
@@ -22,7 +22,7 @@ action_admin_configure:
action_delete
:
pattern
:
'
admin/config/system/actions/configure/{action}/delete'
defaults
:
_
form
:
'
\Drupal\action\Form\D
elete
Form
'
_
entity_form
:
'
action.d
elete'
requirements
:
_permission
:
'
administer
actions'
core/modules/action/lib/Drupal/action/Form/DeleteForm.php
→
core/modules/action/lib/Drupal/action/Form/
Action
DeleteForm.php
View file @
73fbcf80
...
...
@@ -2,72 +2,47 @@
/**
* @file
* Contains \Drupal\action\Form\DeleteForm.
* Contains \Drupal\action\Form\
Action
DeleteForm.
*/
namespace
Drupal\action\Form
;
use
Drupal\Core\Form\ConfirmFormBase
;
use
Drupal\system\ActionConfigEntityInterface
;
use
Drupal\Core\Entity\EntityConfirmFormBase
;
/**
* Builds a form to delete an action.
*/
class
DeleteForm
extends
ConfirmFormBase
{
/**
* The action to be deleted.
*
* @var \Drupal\system\ActionConfigEntityInterface
*/
protected
$action
;
class
ActionDeleteForm
extends
EntityConfirmFormBase
{
/**
* {@inheritdoc}
*/
p
rotected
function
getQuestion
()
{
return
t
(
'Are you sure you want to delete the action %action?'
,
array
(
'%action'
=>
$this
->
action
->
label
()));
p
ublic
function
getQuestion
()
{
return
t
(
'Are you sure you want to delete the action %action?'
,
array
(
'%action'
=>
$this
->
entity
->
label
()));
}
/**
* {@inheritdoc}
*/
p
rotected
function
getConfirmText
()
{
p
ublic
function
getConfirmText
()
{
return
t
(
'Delete'
);
}
/**
* {@inheritdoc}
*/
p
rotected
function
getCancelPath
()
{
p
ublic
function
getCancelPath
()
{
return
'admin/config/system/actions'
;
}
/**
* {@inheritdoc}
*/
public
function
getFormID
()
{
return
'action_admin_delete_form'
;
}
/**
* {@inheritdoc}
*/
public
function
buildForm
(
array
$form
,
array
&
$form_state
,
ActionConfigEntityInterface
$action
=
NULL
)
{
$this
->
action
=
$action
;
return
parent
::
buildForm
(
$form
,
$form_state
);
}
/**
* {@inheritdoc}
*/
public
function
submitForm
(
array
&
$form
,
array
&
$form_state
)
{
$this
->
action
->
delete
();
public
function
submit
(
array
$form
,
array
&
$form_state
)
{
$this
->
entity
->
delete
();
watchdog
(
'user'
,
'Deleted action %aid (%action)'
,
array
(
'%aid'
=>
$this
->
action
->
id
(),
'%action'
=>
$this
->
action
->
label
()));
drupal_set_message
(
t
(
'Action %action was deleted'
,
array
(
'%action'
=>
$this
->
action
->
label
())));
watchdog
(
'user'
,
'Deleted action %aid (%action)'
,
array
(
'%aid'
=>
$this
->
entity
->
id
(),
'%action'
=>
$this
->
entity
->
label
()));
drupal_set_message
(
t
(
'Action %action was deleted'
,
array
(
'%action'
=>
$this
->
entity
->
label
())));
$form_state
[
'redirect'
]
=
'admin/config/system/actions'
;
}
...
...
core/modules/aggregator/aggregator.module
View file @
73fbcf80
...
...
@@ -370,27 +370,6 @@ function aggregator_save_category($edit) {
}
}
/**
* Removes all items from a feed.
*
* @param \Drupal\aggregator\Plugin\Core\Entity\Feed $feed
* An object describing the feed to be cleared.
*/
function
aggregator_remove
(
Feed
$feed
)
{
// Call \Drupal\aggregator\Plugin\ProcessorInterface::remove() on all
// processors.
$manager
=
Drupal
::
service
(
'plugin.manager.aggregator.processor'
);
foreach
(
$manager
->
getDefinitions
()
as
$id
=>
$definition
)
{
$manager
->
createInstance
(
$id
)
->
remove
(
$feed
);
}
// Reset feed.
$feed
->
checked
->
value
=
0
;
$feed
->
hash
->
value
=
''
;
$feed
->
etag
->
value
=
''
;
$feed
->
modified
->
value
=
0
;
$feed
->
save
();
}
/**
* Checks a news feed for new items.
*
...
...
core/modules/aggregator/aggregator.routing.yml
View file @
73fbcf80
...
...
@@ -15,14 +15,14 @@ aggregator_admin_settings:
aggregator_feed_items_delete
:
pattern
:
'
/admin/config/services/aggregator/remove/{aggregator_feed}'
defaults
:
_
form
:
'
\Drupal\aggregator\Form\FeedItemsDelete
'
_
entity_form
:
'
aggregator_feed.remove_items
'
requirements
:
_permission
:
'
administer
news
feeds'
aggregator_feed_delete
:
pattern
:
'
/admin/config/services/aggregator/delete/feed/{aggregator_feed}'
defaults
:
_form
:
'
\Drupal\
aggregator
\Form\F
eed
D
elete'
_
entity_
form
:
'
aggregator
_f
eed
.d
elete'
requirements
:
_permission
:
'
administer
news
feeds'
...
...
core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.php
View file @
73fbcf80
...
...
@@ -14,4 +14,9 @@
*/
interface
FeedInterface
extends
ContentEntityInterface
{
/**
* Removes all items from a feed.
*/
public
function
removeItems
();
}
core/modules/aggregator/lib/Drupal/aggregator/Form/FeedDelete.php
→
core/modules/aggregator/lib/Drupal/aggregator/Form/FeedDelete
Form
.php
View file @
73fbcf80
<?php
/**
* @file
* Contains \Drupal\aggregator\Form\FeedDelete.
* Contains \Drupal\aggregator\Form\FeedDelete
Form
.
*/
namespace
Drupal\aggregator\Form
;
use
Drupal\Core\Form\ConfirmFormBase
;
use
Drupal\aggregator\Plugin\Core\Entity\Feed
;
use
Drupal\Core\Entity\EntityNGConfirmFormBase
;
/**
* Provides a form for deleting a feed.
*/
class
FeedDelete
extends
ConfirmFormBase
{
/**
* The feed the being deleted.
*
* @var \Drupal\aggregator\Plugin\Core\Entity\Feed
*/
protected
$feed
;
class
FeedDeleteForm
extends
EntityNGConfirmFormBase
{
/**
* {@inheritdoc}
*/
public
function
get
FormID
()
{
return
'aggregator_feed_delete_form'
;
public
function
get
Question
()
{
return
t
(
'Are you sure you want to delete the feed %feed?'
,
array
(
'%feed'
=>
$this
->
entity
->
label
()))
;
}
/**
* {@inheritdoc}
*/
protected
function
getQuestion
()
{
return
t
(
'Are you sure you want to delete the feed %feed?'
,
array
(
'%feed'
=>
$this
->
feed
->
label
()));
}
/**
* {@inheritdoc}
*/
protected
function
getCancelPath
()
{
public
function
getCancelPath
()
{
return
'admin/config/services/aggregator'
;
}
/**
* {@inheritdoc}
*/