Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
c6929a8
Case 29367; Issue 2930747; patch applied
Feb 7, 2018
c6e7de5
Case 29367; refactor settings form
Feb 7, 2018
56cd384
Case 29367; fixing default_value empty error
Feb 7, 2018
e21aabc
Case 29367; fix the patch issue and refactor to exclude the relevant …
Feb 7, 2018
2ddabad
Case 29367; remove .orig file left over from patch
Feb 7, 2018
48ccdd1
Case 29367; remove .orig file left over from patch
Feb 7, 2018
c639513
Case 29367; exclude paragraph fields
Feb 7, 2018
81f6a46
Case 29367; fix deprecated functions
Feb 8, 2018
218eeb5
Case 29367; final deprecated functions and using interfaces
Feb 8, 2018
173bfc7
Case 29367; correctly use services and update more deprecated functions
Feb 8, 2018
e946d6f
Case 29367; added missing @params
Feb 13, 2018
f66d329
Case 29367; check paragraph bundle and fields before excluding
Feb 13, 2018
f277398
Case 29367; add missing params
Feb 13, 2018
b7deba6
Case 29367; dont save form id and other settings in config
Feb 13, 2018
3376449
Case 29367; remove config fix to add to its own issue and branch
Feb 13, 2018
5f01eb2
Case 29367; got in a drupal issue muddle, config fix belongs here
Feb 13, 2018
8ba77af
Case 29367; remove debugging code
Feb 13, 2018
174dbfc
Merge from 8.x-1.x
marcelovani Aug 14, 2018
4b19cad
Renamed configuration
marcelovani Aug 14, 2018
fa09d99
Renamed route
marcelovani Aug 14, 2018
499e663
Cleaning up
marcelovani Aug 14, 2018
7e9fe73
Logic error, Use dependency injection
marcelovani Aug 14, 2018
8d81bfb
Use dependency injection
marcelovani Aug 14, 2018
b165393
Logic error
marcelovani Aug 14, 2018
56c97cb
Logic error
marcelovani Aug 14, 2018
946d4d4
Logic error
marcelovani Aug 14, 2018
9719025
Logic error
marcelovani Aug 14, 2018
a05924f
Fixed php warning
marcelovani Aug 14, 2018
907e13d
Merge from 8.x-1.x
marcelovani Oct 16, 2018
2f4ec68
Merge from 8.x-1.x
marcelovani Oct 16, 2018
40c25ff
changed order
marcelovani Oct 16, 2018
7ab665e
changed order
marcelovani Oct 16, 2018
01ff0d7
Fixed php warning
marcelovani Oct 16, 2018
999284e
Fixed ajax form
marcelovani Oct 16, 2018
4df05b4
Fixed ajax callback for paragraphs. Improved UI to make it more intui…
marcelovani Oct 17, 2018
6ccb534
Fixed config structure
marcelovani Oct 17, 2018
46d47f8
Fixing form settings load
marcelovani Oct 18, 2018
041b383
Fixed config form
marcelovani Oct 18, 2018
5e9d1fb
Major refactor to reuse code
marcelovani Oct 18, 2018
9ee2cf9
Cleaning up
marcelovani Oct 18, 2018
7204057
Renamed everything
marcelovani Oct 18, 2018
8fc2621
Obey config. Reformated code.
marcelovani Oct 22, 2018
3fd727a
Committed paragraphs form
marcelovani Oct 22, 2018
3b769e8
Renamed files
marcelovani Oct 22, 2018
86001ac
Renamed files
marcelovani Oct 22, 2018
25763cd
Call constructor
marcelovani Oct 22, 2018
efbd7f8
Fixing variable definitions
marcelovani Oct 22, 2018
3022947
Namespaces
marcelovani Oct 22, 2018
f686c59
Adding tests
marcelovani Oct 22, 2018
ba35e4f
Merge from schema branch
marcelovani Oct 24, 2018
a19e72d
Merge branch '3008519-automated_tests' into 8.x-1.x_2930747_exclude_f…
marcelovani Oct 24, 2018
6e57a34
Updated schema
marcelovani Oct 24, 2018
8bc2fe2
Updating tests
marcelovani Oct 24, 2018
e1f8fed
Updating tests
marcelovani Oct 24, 2018
6433205
Updating tests
marcelovani Oct 24, 2018
c327375
Updating tests
marcelovani Oct 25, 2018
7cb28c9
Updating tests
marcelovani Oct 25, 2018
074eb38
Fixed logic
marcelovani Oct 25, 2018
dd92503
Fixed logic
marcelovani Oct 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/install/quick_node_clone.settings.yml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
text_to_prepend_to_title: "Clone of"
exclude:
node: { }
paragraph: { }
13 changes: 13 additions & 0 deletions config/schema/quick_node_clone.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ quick_node_clone.settings:
type: config_object
label: 'Quick Node Clone settings'
mapping:
exclude:
type: sequence
label: 'Exclude list'
sequence:
type: sequence
label: 'Entity type'
sequence:
type: sequence
label: 'Bundle Name'
sequence:
type: string
label: 'Field Name'
text_to_prepend_to_title:
type: string
label: 'Text to prepend to title'

2 changes: 2 additions & 0 deletions quick_node_clone.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ core: 8.x
configure: quick_node_clone.settingsform
dependencies:
- drupal:node
test_dependencies:
- paragraphs:paragraphs
12 changes: 12 additions & 0 deletions quick_node_clone.links.task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,15 @@ quick_node_clone.node.quick_clone:
base_route: entity.node.canonical
title: 'Clone'
weight: 30

quick_node_clone.node.settings:
route_name: quick_node_clone.settingsform
base_route: quick_node_clone.settingsform
title: 'Node'
weight: -10

quick_node_clone.paragraph_settings_form:
route_name: quick_node_clone.paragraph_settings_form
base_route: quick_node_clone.settingsform
title: 'Paragraph'
weight: 10
9 changes: 8 additions & 1 deletion quick_node_clone.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ quick_node_clone.node.quick_clone:
quick_node_clone.settingsform:
path: '/admin/config/quick-node-clone'
defaults:
_form: '\Drupal\quick_node_clone\Form\QuickNodeCloneSettingForm'
_form: '\Drupal\quick_node_clone\Form\QuickNodeCloneNodeSettingsForm'
_title: 'Quick Node Clone Setting'
requirements:
_permission: 'Administer Quick Node Clone Settings'
quick_node_clone.paragraph_settings_form:
path: '/admin/config/quick-node-clone-paragraph'
defaults:
_form: '\Drupal\quick_node_clone\Form\QuickNodeCloneParagraphSettingsForm'
_title: 'Quick Node Paragraph Clone Setting'
requirements:
_permission: 'Administer Quick Node Clone Settings'
2 changes: 1 addition & 1 deletion quick_node_clone.services.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
quick_node_clone.entity.form_builder:
class: Drupal\quick_node_clone\Entity\QuickNodeCloneEntityFormBuilder
arguments: ['@entity.manager', '@form_builder']
arguments: ['@form_builder', '@entity_type.bundle.info', '@config.factory', '@module_handler', '@entity_type.manager']
quick_node_clone.address_event_subscriber:
class: Drupal\quick_node_clone\EventSubscriber\AddressEventSubscriber
tags:
Expand Down
125 changes: 114 additions & 11 deletions src/Entity/QuickNodeCloneEntityFormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,75 @@

namespace Drupal\quick_node_clone\Entity;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Entity\EntityFormBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormState;
use Drupal\Core\Entity\EntityInterface;
use Drupal\node\Entity\Node;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Builds entity forms.
*/
class QuickNodeCloneEntityFormBuilder extends EntityFormBuilder {
protected $formBuilder;
/**
* The Entity Bundle Type Info.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/**
* The Config Factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The Module Handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The Entity Type Manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity_type.bundle.info'),
$container->get('config.factory'),
$container->get('module_handler'),
$container->get('entity_type.manager')
);
}

/**
* QuickNodeCloneEntityFormBuilder constructor.
*
* @param \Drupal\Core\Form\FormBuilderInterface $formBuilder
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entityTypeBundleInfo
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
*/
public function __construct(FormBuilderInterface $formBuilder, EntityTypeBundleInfoInterface $entityTypeBundleInfo, ConfigFactoryInterface $configFactory, ModuleHandlerInterface $moduleHandler, EntityTypeManagerInterface $entityTypeManager) {
$this->formBuilder = $formBuilder;
$this->entityTypeBundleInfo = $entityTypeBundleInfo;
$this->configFactory = $configFactory;
$this->moduleHandler = $moduleHandler;
$this->entityTypeManager = $entityTypeManager;
}

/**
* {@inheritdoc}
Expand All @@ -26,20 +86,29 @@ public function getForm(EntityInterface $original_entity, $operation = 'default'
/** @var \Drupal\node\Entity\Node $translated_node */
$translated_node = $new_node->getTranslation($langcode);
$translated_node = $this->cloneParagraphs($translated_node);
\Drupal::moduleHandler()->alter('cloned_node', $translated_node);
$this->moduleHandler->alter('cloned_node', $translated_node);

// Unset excluded fields.
$config_name = 'exclude.node.' . $translated_node->getType();
if ($exclude_fields = $this->getConfigSettings($config_name)) {
foreach ($exclude_fields as $key => $field) {
unset($translated_node->{$field});
}
}

$prepend_text = "";
$config = \Drupal::config('quick_node_clone.settings');
if (!empty($config->get('text_to_prepend_to_title'))) {
$prepend_text = $config->get('text_to_prepend_to_title') . " ";
$config = $this->getConfigSettings('text_to_prepend_to_title');
if (!empty($config)) {
$prepend_text = $config . " ";
}
$translated_node->setTitle(t($prepend_text . '@title', ['@title' => $original_entity->getTitle()], ['langcode' => $langcode]));
$translated_node->setTitle(t($prepend_text . '@title', ['@title' => $translated_node->getTitle()], ['langcode' => $langcode]));
}

// Get the form object for the entity defined in entity definition.
$form_object = $this->entityManager->getFormObject($new_node->getEntityTypeId(), $operation);
// Get the form object for the entity defined in entity definition
$form_object = $this->entityTypeManager->getFormObject($translated_node->getEntityTypeId(), $operation);

// Assign the form's entity to our duplicate!
$form_object->setEntity($new_node);
$form_object->setEntity($translated_node);

$form_state = (new FormState())->setFormState($form_state_additions);
$new_form = $this->formBuilder->buildForm($form_object, $form_state);
Expand Down Expand Up @@ -72,7 +141,6 @@ public function cloneParagraphs(Node $node) {
$field_settings = $field_storage_definition->getSettings();
$field_name = $field_storage_definition->getName();
if (isset($field_settings['target_type']) && $field_settings['target_type'] == "paragraph") {

if (!$node->get($field_name)->isEmpty()) {
foreach ($node->get($field_name) as $value) {
if ($value->entity) {
Expand All @@ -81,14 +149,49 @@ public function cloneParagraphs(Node $node) {
$field_storage_definition = $field_definition->getFieldStorageDefinition();
$pfield_settings = $field_storage_definition->getSettings();
$pfield_name = $field_storage_definition->getName();
\Drupal::moduleHandler()->alter('cloned_node_paragraph_field', $value->entity, $pfield_name, $pfield_settings);

// Check whether this field is excluded and if so unset.
if ($this->excludeParagraphField($pfield_name, $value->entity->bundle())) {
unset($value->entity->{$pfield_name});
}

$this->moduleHandler->alter('cloned_node_paragraph_field', $value->entity, $pfield_name, $pfield_settings);
}
}
}
}
}
}

return $node;
}

/**
* Check whether to exclude the paragraph field.
*
* @param $field_name
* @param $bundle_name
*
* @return bool|NULL
*/
public function excludeParagraphField($field_name, $bundle_name) {
$config_name = 'exclude.paragraph.' . $bundle_name;
if ($exclude_fields = $this->getConfigSettings($config_name)) {
return in_array($field_name, $exclude_fields);
}
}

/**
* Get the settings.
*
* @param $value
*
* @return array|mixed|null
*/
public function getConfigSettings($value) {
$settings = $this->configFactory->get('quick_node_clone.settings')
->get($value);

return $settings;
}
}
Loading