Skip to content

[5.0][Events] Fix backward compatibility for onAfterRenderModules#41497

Merged
HLeithner merged 1 commit intojoomla:5.0-devfrom
Fedik:event-mod-bc
Sep 2, 2023
Merged

[5.0][Events] Fix backward compatibility for onAfterRenderModules#41497
HLeithner merged 1 commit intojoomla:5.0-devfrom
Fedik:event-mod-bc

Conversation

@Fedik
Copy link
Member

@Fedik Fedik commented Aug 28, 2023

Summary of Changes

Fix backward compatibility for onAfterRenderModules

Testing Instructions

Add following listener to Sef system plugin:

public function onAfterRenderModules(&$value) {
      $value .= ' aaaa';
}

Open the site, and check rendered modules

Actual result BEFORE applying this Pull Request

Nothing changed

Expected result AFTER applying this Pull Request

Every module position now have 'aaaa' appended

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:
  • No documentation changes for docs.joomla.org needed
  • Pull Request link for manual.joomla.org: New Event classes Manual#177
  • No documentation changes for manual.joomla.org needed

Reference:

@HLeithner
Copy link
Member

Merging this as with code review and based on the other similar PRs, before beta1 to get enough feedback for final release.

Additional ArrayProxy is nothing we plan to have for ever right? because it only hides the & reference, Also I think we should convert the array back after we triggered the event with them?

@HLeithner HLeithner merged commit 8297e3a into joomla:5.0-dev Sep 2, 2023
@Fedik Fedik deleted the event-mod-bc branch September 2, 2023 14:56
@Fedik
Copy link
Member Author

Fedik commented Sep 2, 2023

Additional ArrayProxy is nothing we plan to have for ever right? because it only hides the & reference

Yeah, it for replacement of array with reference.
There many events that use "array" editing.
Tricky thing.

Also I think we should convert the array back after we triggered the event with them?

The changes applied to original array, converting it back is unnecessary.

@HLeithner
Copy link
Member

Sure but the thing is we don't want that the Plugin manipulate the array directly?

@Fedik
Copy link
Member Author

Fedik commented Sep 3, 2023

Yes, that the idea. because it hard to debug where the data gets modified by reference.
With ArrayProxy it at least possible to attach debugger to ArrayProxy::offsetSet().
We have around 15-20 events using array modification.

Unfortunately, there also events where we mix object/array for $data,

@HLeithner
Copy link
Member

we should make this consistent... maybe not in 5 but later

@Fedik
Copy link
Member Author

Fedik commented Sep 3, 2023

TBH, I have no idea how it can be done, for now and in future.

@Fedik
Copy link
Member Author

Fedik commented Sep 3, 2023

Maybe in one of next beta, I will add updateData() method, to all events with $data.
This will enforce developers to use $event->updateData($data);, instead of editing $data "in place", to prepare them for future.

Similar what we made for strings $downloadEvent->updateUrl($url);

Need to think.

@HLeithner
Copy link
Member

We have $event->setData() don't we have this to update arguments? (when not immutable?)

@Fedik
Copy link
Member Author

Fedik commented Sep 3, 2023

$event->setData()

It is part of argument validation, it cannot be public, or you get a loop. (Do not ask why)

$methodName = 'set' . ucfirst($name);
if (method_exists($this, $methodName)) {
$value = $this->{$methodName}($value);
}
return parent::setArgument($name, $value);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants