Commit 68ec5f7a authored by jefuri's avatar jefuri Committed by Berdir
Browse files

Issue #3000788 by jefuri, Anybody: Add "duplicate" action for pathauto...

Issue #3000788 by jefuri, Anybody: Add "duplicate" action for pathauto patterns (clone existing entry values)
parent 66b0fda9
......@@ -15,6 +15,15 @@ entity.pathauto_pattern.add_form:
requirements:
_permission: 'administer pathauto'
entity.pathauto_pattern.duplicate_form:
path: '/admin/config/search/path/patterns/{pathauto_pattern}/duplicate'
defaults:
_entity_form: 'pathauto_pattern.duplicate'
_title: 'Duplicate Pathauto pattern'
tempstore_id: 'pathauto.pattern'
requirements:
_permission: 'administer pathauto'
pathauto.settings.form:
path: '/admin/config/search/path/settings'
defaults:
......
......@@ -21,6 +21,7 @@ use Drupal\pathauto\PathautoPatternInterface;
* "list_builder" = "Drupal\pathauto\PathautoPatternListBuilder",
* "form" = {
* "default" = "Drupal\pathauto\Form\PatternEditForm",
* "duplicate" = "Drupal\pathauto\Form\PatternDuplicateForm",
* "delete" = "Drupal\Core\Entity\EntityDeleteForm",
* "enable" = "Drupal\pathauto\Form\PatternEnableForm",
* "disable" = "Drupal\pathauto\Form\PatternDisableForm"
......@@ -57,7 +58,8 @@ use Drupal\pathauto\PathautoPatternInterface;
* "edit-form" = "/admin/config/search/path/patterns/{pathauto_pattern}",
* "delete-form" = "/admin/config/search/path/patterns/{pathauto_pattern}/delete",
* "enable" = "/admin/config/search/path/patterns/{pathauto_pattern}/enable",
* "disable" = "/admin/config/search/path/patterns/{pathauto_pattern}/disable"
* "disable" = "/admin/config/search/path/patterns/{pathauto_pattern}/disable",
* "duplicate-form" = "/admin/config/search/path/patterns/{pathauto_pattern}/duplicate"
* }
* )
*/
......
<?php
namespace Drupal\pathauto\Form;
use Drupal\Core\Entity\EntityInterface;
/**
* Provides the pathauto pattern duplicate form.
*/
class PatternDuplicateForm extends PatternEditForm {
/**
* {@inheritdoc}
*/
public function setEntity(EntityInterface $entity) {
$this->entity = $entity->createDuplicate();
return $this;
}
}
......@@ -48,4 +48,24 @@ class PathautoPatternListBuilder extends DraggableListBuilder {
return $row + parent::buildRow($entity);
}
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
/** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
$operations = parent::getDefaultOperations($entity);
if (!$entity->hasLinkTemplate('duplicate-form')) {
return $operations;
}
$operations['duplicate'] = [
'title' => t('Duplicate'),
'weight' => 0,
'url' => $this->ensureDestination($entity->toUrl('duplicate-form')),
];
return $operations;
}
}
......@@ -146,6 +146,11 @@ class PathautoUiTest extends WebTestBase {
// Check that the pattern weight did not change.
$this->assertOptionSelected('edit-entities-page-pattern-weight', '4');
$edit = array('label' => 'Test Duplicate', 'id' => 'page_pattern_test_duplicate');
$this->drupalPostForm('/admin/config/search/path/patterns/page_pattern/duplicate', $edit, t('Save'));
$this->assertText('Pattern Test Duplicate saved.');
PathautoPattern::load('page_pattern_test_duplicate')->delete();
// Disable workflow.
$this->drupalGet('/admin/config/search/path/patterns');
$this->assertNoLink(t('Enable'));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment