Skip to content
Snippets Groups Projects
Commit 8c89dc23 authored by kksandr's avatar kksandr Committed by Mark Dorison
Browse files

Issue #3334865: Make support for groups optional

parent 188e0d46
Branches
Tags
1 merge request!23Issue #3334865 by kksandr: Make support for groups optional
Pipeline #329174 failed
......@@ -3,3 +3,4 @@ exclude:
node: { }
paragraph: { }
clone_status: false
create_group_relationships: true
......@@ -20,3 +20,6 @@ quick_node_clone.settings:
clone_status:
type: boolean
label: 'Clone publication status of original?'
create_group_relationships:
type: boolean
label: 'Create group relationships?'
<?php
/**
* @file
* Install, update and uninstall functions for the Quick Node Clone module.
*/
/**
* Setting the default value for the new "create_group_relationships" option.
*/
function quick_node_clone_update_9000(&$sandbox) {
\Drupal::configFactory()->getEditable('quick_node_clone.settings')
->set('create_group_relationships', TRUE)
->save();
}
......@@ -135,7 +135,7 @@ class QuickNodeCloneEntityFormBuilder extends EntityFormBuilder {
// Get and store groups of original entity, if any.
$groups = [];
if ($this->moduleHandler->moduleExists('gnode')) {
if ($this->getConfigSettings('create_group_relationships') && $this->moduleHandler->moduleExists('gnode')) {
$relation_class = class_exists(GroupContent::class) ? GroupContent::class : GroupRelationship::class;
/** @var \Drupal\Core\Entity\ContentEntityInterface $original_entity */
foreach ($relation_class::loadByEntity($original_entity) as $group_relationship) {
......
......@@ -5,6 +5,7 @@ namespace Drupal\quick_node_clone\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\field\Entity\FieldConfig;
......@@ -38,6 +39,13 @@ abstract class QuickNodeCloneEntitySettingsForm extends ConfigFormBase implement
*/
protected $entityTypeBundleInfo;
/**
* The Module Handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The machine name of the entity type.
*
......@@ -53,7 +61,8 @@ abstract class QuickNodeCloneEntitySettingsForm extends ConfigFormBase implement
return new static(
$container->get('config.factory'),
$container->get('entity_field.manager'),
$container->get('entity_type.bundle.info')
$container->get('entity_type.bundle.info'),
$container->get('module_handler')
);
}
......@@ -87,12 +96,15 @@ abstract class QuickNodeCloneEntitySettingsForm extends ConfigFormBase implement
* The entity field manager service.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entityTypeBundleInfo
* The entity type bundle info provider.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* The module handler service.
*/
public function __construct(ConfigFactoryInterface $configFactory, EntityFieldManagerInterface $entityFieldManager, EntityTypeBundleInfoInterface $entityTypeBundleInfo) {
public function __construct(ConfigFactoryInterface $configFactory, EntityFieldManagerInterface $entityFieldManager, EntityTypeBundleInfoInterface $entityTypeBundleInfo, ModuleHandlerInterface $moduleHandler) {
parent::__construct($configFactory);
$this->configFactory = $configFactory;
$this->entityFieldManager = $entityFieldManager;
$this->entityTypeBundleInfo = $entityTypeBundleInfo;
$this->moduleHandler = $moduleHandler;
}
/**
......@@ -100,6 +112,13 @@ abstract class QuickNodeCloneEntitySettingsForm extends ConfigFormBase implement
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['create_group_relationships'] = [
'#type' => 'checkbox',
'#title' => $this->t('Create group relationships?'),
'#default_value' => $this->getSettings('create_group_relationships'),
'#description' => $this->t('If the checkbox is selected and the Group module is enabled, group relationships will be created.'),
'#disabled' => !$this->moduleHandler->moduleExists('gnode'),
];
$form['exclude'] = [
'#type' => 'fieldset',
'#title' => $this->t('Exclusion list'),
......@@ -187,7 +206,10 @@ abstract class QuickNodeCloneEntitySettingsForm extends ConfigFormBase implement
}
// Save config.
$this->config('quick_node_clone.settings')->set('exclude.' . $this->getEntityTypeId(), $bundle_names)->save();
$this->config('quick_node_clone.settings')
->set('exclude.' . $this->getEntityTypeId(), $bundle_names)
->set('create_group_relationships', $form_values['create_group_relationships'])
->save();
// Display a success message depending on form_id.
if ($form['#form_id'] === 'quick_node_clone_paragraph_setting_form') {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment