Skip to content
Snippets Groups Projects
Commit 74c1594e authored by Steven Ayers's avatar Steven Ayers
Browse files

Merge branch '3075889-add-option-to' into '8.x-1.x'

Issue #3075889 by bluegeek9: Add option to have cloned node publish status default to unpublished

See merge request !43
parents 779cec05 29ea7228
No related branches found
No related tags found
No related merge requests found
Pipeline #427821 passed with warnings
......@@ -2,5 +2,5 @@ text_to_prepend_to_title: "Clone of"
exclude:
node: { }
paragraph: { }
clone_status: false
clone_status: default
create_group_relationships: true
......@@ -18,8 +18,8 @@ quick_node_clone.settings:
type: string
label: 'Text to prepend to title'
clone_status:
type: boolean
label: 'Clone publication status of original?'
type: string
label: 'Cloned node status'
create_group_relationships:
type: boolean
label: 'Create group relationships?'
......@@ -12,3 +12,20 @@ function quick_node_clone_update_8119(&$sandbox) {
// Clear cache.
drupal_flush_all_caches();
}
/**
* Adds more options for clone node's status.
*/
function quick_node_clone_update_8120() {
// Editable settings.
$settings = \Drupal::service('config.factory')->getEditable('quick_node_clone.settings');
$clone_status = $settings->get('clone_status');
if ($clone_status) {
$settings->set('clone_status', 'original');
$settings->save();
}
else {
$settings->set('clone_status', 'default');
$settings->save();
}
}
......@@ -146,10 +146,26 @@ class QuickNodeCloneEntityFormBuilder extends EntityFormBuilder {
if (!empty($title_prepend_config)) {
$prepend_text = $title_prepend_config . " ";
}
$clone_status_config = $this->getConfigSettings('clone_status');
if (!$clone_status_config) {
switch ($clone_status_config) {
case 'original':
break;
case 'published':
$translated_node->setPublished();
break;
case 'unpublished':
$translated_node->setUnpublished();
break;
case 'default':
default:
$key = $translated_node->getEntityType()->getKey('published');
$translated_node->set($key, $default_bundle_status);
break;
}
$translated_node->setTitle($this->t('@prepend_text@title',
......
......@@ -35,11 +35,19 @@ class QuickNodeCloneNodeSettingsForm extends QuickNodeCloneEntitySettingsForm {
'#default_value' => $this->getSettings('text_to_prepend_to_title'),
'#description' => $this->t('Enter text to add to the title of a cloned node to help content editors. A space will be added between this text and the title. Example: "Clone of"'),
];
$default_clone_status = $this->getSettings('clone_status');
$form['clone_status'] = [
'#type' => 'checkbox',
'#title' => $this->t('Clone publication status of original?'),
'#default_value' => $this->getSettings('clone_status'),
'#description' => $this->t('If unchecked, the publication status of the clone will be equal to the default of the content type.'),
'#type' => 'radios',
'#title' => $this->t('Publication status'),
'#description' => $this->t('What should the cloned status be?'),
'#default_value' => $default_clone_status,
'#options' => [
'default' => $this->t('Default - Node type default'),
'original' => $this->t('Original - Clone will have the same status as the original'),
'published' => $this->t('Published'),
'unpublished' => $this->t('Unpublished'),
],
];
return parent::buildForm($form, $form_state);
......@@ -51,8 +59,12 @@ class QuickNodeCloneNodeSettingsForm extends QuickNodeCloneEntitySettingsForm {
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state->cleanValues();
$form_values = $form_state->getValues();
$this->config('quick_node_clone.settings')->set('text_to_prepend_to_title', $form_values['text_to_prepend_to_title'])->save();
$this->config('quick_node_clone.settings')->set('clone_status', $form_values['clone_status'])->save();
$settings = $this->config('quick_node_clone.settings');
$settings
->set('text_to_prepend_to_title', $form_values['text_to_prepend_to_title'])
->set('clone_status', $form_values['clone_status'])
->save();
parent::submitForm($form, $form_state);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment