- Issue created by @audiomason
- Open in Jenkins β Open on Drupal.org βCore: 9.5.x + Environment: PHP 8.0 & MySQL 5.7 (--ignore-platform-reqs)last update
over 1 year ago 79 pass - last update
over 1 year ago 79 pass - πΊπ¦Ukraine knyshuk.vova
@audiomason, nice job for finding such an issue. I have some adjustments for your patch.
It's better to use a setter method setEntityValue(), which indicates that change is intentional and controlled, rather than getting the reference of the value and change it directly.
public function __construct(&$value, SalesforceMappingFieldPluginInterface $fieldPlugin, MappedObjectInterface $mappedObject) { $this->entityValue = &$value; // rest of code... } /** * Setter for entity value. * * @param mixed $value * The value to be assigned. */ public function setEntityValue($value) { $this->entityValue = $value; }
I was having the same problem, but found the way to do this without a patch.
class MySalesforceSubscriber implements EventSubscriberInterface { public function onSalesforcePullEntityValue(SalesforcePullEntityValueEvent $event) { $value = $event->getEntityValue(); if (is_null($value->getValue())) { $value->setValue(42); } } public static function getSubscribedEvents() { return [ SalesforceEvents::PULL_ENTITY_VALUE => ['onSalesforcePullEntityValue'], ]; } }
You need to use setValue() and you don't need to pass by reference.
This is not clear, an example added to SalesforceExampleSubscriber would be helpful.
Also, should the pass by reference be removed from the __construct in SalesforcePullEntityValueEvent.php? As far as I can tell it does nothing.- πΊπ¦Ukraine knyshuk.vova
Confirm that solution from #5resolves the issue.
I agree that the example should be added to SalesforceExampleSubscriber