diff --git a/config/install/quick_node_clone.settings.yml b/config/install/quick_node_clone.settings.yml index 47b9a5cb0e107bbfdc2284f253652c434c5e62f2..d5a810e0b8cfe73b815689787929fa9c31fcc9c5 100644 --- a/config/install/quick_node_clone.settings.yml +++ b/config/install/quick_node_clone.settings.yml @@ -2,5 +2,5 @@ text_to_prepend_to_title: "Clone of" exclude: node: { } paragraph: { } -clone_status: false +clone_status: default create_group_relationships: true diff --git a/config/schema/quick_node_clone.schema.yml b/config/schema/quick_node_clone.schema.yml index 08dceb4a86ba89856e8bf86c98cad3d95b84aab7..f4ea629168c5da10cedc30bcb81fbc9d072e9268 100644 --- a/config/schema/quick_node_clone.schema.yml +++ b/config/schema/quick_node_clone.schema.yml @@ -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?' diff --git a/quick_node_clone.install b/quick_node_clone.install index 2d99cf8182cbdf5d14c2a93097e21994706213f9..4238c7cd89e94e185bdcd06b7103dce42cb66a8f 100644 --- a/quick_node_clone.install +++ b/quick_node_clone.install @@ -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(); + } +} diff --git a/src/Entity/QuickNodeCloneEntityFormBuilder.php b/src/Entity/QuickNodeCloneEntityFormBuilder.php index 8592c1966e57abea75dcbd143c5e9a245d0286b3..742b3b0b78bb90b301fa40c58f1bbf9ad08cb83d 100755 --- a/src/Entity/QuickNodeCloneEntityFormBuilder.php +++ b/src/Entity/QuickNodeCloneEntityFormBuilder.php @@ -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) { - $key = $translated_node->getEntityType()->getKey('published'); - $translated_node->set($key, $default_bundle_status); + 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', diff --git a/src/Form/QuickNodeCloneNodeSettingsForm.php b/src/Form/QuickNodeCloneNodeSettingsForm.php index 1d89dc74690b1e555365079a691fb1a3393f2c8b..1c4722e9c323ee249a39c68243942b6924e94193 100644 --- a/src/Form/QuickNodeCloneNodeSettingsForm.php +++ b/src/Form/QuickNodeCloneNodeSettingsForm.php @@ -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); }