- 🇬🇧United Kingdom jonathanshaw Stroud, UK
This looks like a good solution.
- Status changed to Needs work
almost 2 years ago 5:52pm 30 March 2023 - 🇬🇧United Kingdom jonathanshaw Stroud, UK
Actually I have doubts about the implementation. This uses a generic service that applies to all entity types, but I doubt that the most common use case for customising this is to want to customise it for all entity types.
I'd imagine it's much more common to customise it for a specific entity type based on the specific fields of that entity type. In which case, it would be better if the clone form handler could call out to clone handler so customisation could be done there. A problem though is that fieldIsClonable is a protected method.
Solution:
1. Remove method
fieldIsClonable
fromContentEntityCloneFormBase
.2. Add an
isFieldClonable
method toContentEntityCloneBase
and the relevant interface:public function isFieldClonable(FieldItemListInterface $field) { // For backwards-compatability use a custom fieldIsClonable method if it exists, // otherwise use the clonable field service. if (method_exists('fieldIsClonable')) { trigger_error(E_USER_DEPRECATED, 'fieldIsclonable' is deprecated, override isFieldClonableInstead'); return $this->fieldIsClonable($field->getFieldDefinition()); } return $this->entityCloneClonableField->isClonable($field) }
3. In ContentEntityCloneFormBase call the clone handler:
+ $entity_clone_handler = $this->entityTypeManager->getHandler($entity->getEntityTypeId(), 'entity_clone'); + if ($entity_clone_handler->isFieldClonable($field)) { + $form['recursive'] = array_merge($form['recursive'], $this->getRecursiveFormElement($field_definition, $field_id, $field, $discovered_entities));
- 🇨🇦Canada alberto56
I took @8ballsteve's patch at #27 and made a new version which works with 2.0.0-beta3.
- last update
over 1 year ago 29 pass - last update
over 1 year ago Patch Failed to Apply - last update
over 1 year ago Patch Failed to Apply - last update
over 1 year ago 29 pass - Open on Drupal.org →Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7last update
over 1 year ago Not currently mergeable. - @rajeshreeputra opened merge request.
- last update
over 1 year ago PHPLint Failed - last update
over 1 year ago PHPLint Failed - last update
over 1 year ago PHPLint Failed - Assigned to ankitv18
- last update
over 1 year ago PHPLint Failed - last update
over 1 year ago PHPLint Failed - Issue was unassigned.
- 🇮🇳India ankitv18
@Rajeshreeputra please check below error as tests are not executing for this MR!46
No syntax errors detected in /var/www/html/modules/contrib/entity_clone/src/EntityClone/Content/ContentEntityCloneBase.php
No syntax errors detected in /var/www/html/modules/contrib/entity_clone/src/EntityCloneClonableField.php
--- Errors ---
PHP Parse error: syntax error, unexpected '*', expecting function (T_FUNCTION) or const (T_CONST) in /var/www/html/modules/contrib/entity_clone/src/EntityClone/Content/ContentEntityCloneFormBase.php on line 62
xargs: php: exited with status 255; aborting - last update
over 1 year ago PHPLint Failed - 🇮🇳India vishalkhode
Looks like couple of changes needed:
- Looks like there's a syntax error in MR. See here.
- Use the dependency injection in Class
src/EntityCloneClonableField.php
here - Remove the unused use statement:
use Drupal\Core\Entity\ContentEntityStorageInterface
from Classsrc/EntityClone/Content/ContentEntityCloneFormBase.php
. - Developers won't be able to alter the service because the class
ContentEntityCloneFormBase
needs contractor of class\Drupal\entity_clone\EntityCloneClonableField
. We need to tweak it like:- Create a new interface
EntityCloneClonableFieldInterface
:
namespace Drupal\entity_clone; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemListInterface; /** * The interface for class EntityCloneClonableField. */ interface EntityCloneClonableFieldInterface { /** * Return whether a field can be cloned or not. * * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition * The field definition. * @param \Drupal\Core\Field\FieldItemListInterface $field * The field. * * @return bool * True if the entity can be cloned. * * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException */ public function isClonable(FieldDefinitionInterface $field_definition, FieldItemListInterface $field): bool; }
-
Update the class
ContentEntityCloneFormBase
from:public function __construct( EntityTypeManagerInterface $entity_type_manager, TranslationManager $translation_manager, EntityCloneSettingsManager $entity_clone_settings_manager, ConfigFactoryInterface $config_factory, EntityCloneClonableField $entity_clone_clonable_field) { $this->entityTypeManager = $entity_type_manager; $this->translationManager = $translation_manager; $this->entityCloneSettingsManager = $entity_clone_settings_manager; $this->configFactory = $config_factory; $this->entityCloneClonableField = $entity_clone_clonable_field; }
To:
public function __construct( EntityTypeManagerInterface $entity_type_manager, TranslationManager $translation_manager, EntityCloneSettingsManager $entity_clone_settings_manager, ConfigFactoryInterface $config_factory, EntityCloneClonableFieldInterface $entity_clone_clonable_field) { $this->entityTypeManager = $entity_type_manager; $this->translationManager = $translation_manager; $this->entityCloneSettingsManager = $entity_clone_settings_manager; $this->configFactory = $config_factory; $this->entityCloneClonableField = $entity_clone_clonable_field; }
- Create a new interface
- First commit to issue fork.
- last update
over 1 year ago PHPLint Failed - Status changed to Needs review
over 1 year ago 5:42am 16 June 2023 - last update
over 1 year ago PHPLint Failed - last update
over 1 year ago PHPLint Failed - last update
over 1 year ago PHPLint Failed - Status changed to Needs work
over 1 year ago 8:40am 19 June 2023 - 🇮🇳India vishalkhode
Needs work here, as there are PHP syntax error. The interface can't implement the method. The interface will only define the method and class with implement the method defined in the interface.
- Assigned to chandu7929
- last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass - last update
over 1 year ago 29 pass, 2 fail - last update
over 1 year ago 29 pass, 2 fail - last update
over 1 year ago 30 pass - Issue was unassigned.
- Status changed to Needs review
over 1 year ago 1:34pm 19 June 2023 - Status changed to RTBC
over 1 year ago 1:39pm 19 June 2023 - last update
over 1 year ago 29 pass, 1 fail - last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass - last update
over 1 year ago 29 pass, 1 fail - last update
over 1 year ago 29 pass, 1 fail - last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass - last update
over 1 year ago 29 pass, 2 fail - last update
over 1 year ago 29 pass, 2 fail - last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass - last update
over 1 year ago 29 pass, 2 fail - last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass - last update
over 1 year ago 30 pass -
Rajeshreeputra →
committed ef45b191 on 2.x
Issue #3013286 by Rajeshreeputra, NiCo_O, rzb, 8ballsteve, chandu7929,...
-
Rajeshreeputra →
committed ef45b191 on 2.x
- Status changed to Fixed
over 1 year ago 8:41am 20 June 2023 - 🇮🇳India rajeshreeputra Pune
merged release to follow shortly. Wil release 2.0.0-beta4!
Automatically closed - issue fixed for 2 weeks with no activity.