Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved MVC events #37978

Closed
wants to merge 41 commits into from
Closed

Improved MVC events #37978

wants to merge 41 commits into from

Conversation

Denitz
Copy link
Contributor

@Denitz Denitz commented Jun 4, 2022

Summary of Changes

  1. events_map property moved from FormModel to BaseDatabaseModel because the property is shared by multiple inheritors.
  2. All eventClass params of AbstractEvent::create() calls are shortened to use Classname::class notation instead of using string event classname (easier to find all event class usages vide IDE in 2022).
  3. onAfterDisplay event can modify the output now.
  4. New ListQueryEvent class and onContentListQuery event to modify the list query before executing.
  5. New AfterGetListEvent class and onContentAfterGetList event to modify the list of items after load from database.

Testing Instructions

  1. Apply patch, try to play with custom events via your plugin, i.e.
		// All views return 'my custom HTML'
		public function onAfterDisplay(DisplayEvent $event)
		{
			$event->setArgument('source', 'my custom HTML');
		}

		// All lists are ordered by `a.id`
		public function onContentListQuery(DisplayEvent $event)
		{
			$event->getArgument('query')->order('a.id');
		}

		// All lists' titles are 'OK'
		public function onContentAfterGetList(AfterGetListEvent $event)
		{
			foreach($event->getArgument('list') as $item)
			{
				$item->title = 'OK';
			}
		}

Actual result BEFORE applying this Pull Request

Core Joomla is barely extendable.

Expected result AFTER applying this Pull Request

Core Joomla is extendable.

Documentation Changes Required

No.

@brianteeman
Copy link
Contributor

Is this backwards compatible?

Copy link
Member

@nibra nibra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far; I don't immediately see any b/c breaks. However, this PR should be targeted at 4.2, as it introduces a new feature.

libraries/src/MVC/Model/ListModel.php Outdated Show resolved Hide resolved
libraries/src/MVC/Model/ListModel.php Outdated Show resolved Hide resolved
libraries/src/MVC/Model/ListModel.php Outdated Show resolved Hide resolved
libraries/src/MVC/Model/ListModel.php Outdated Show resolved Hide resolved
libraries/src/MVC/Model/ListModel.php Outdated Show resolved Hide resolved
libraries/src/MVC/View/HtmlView.php Outdated Show resolved Hide resolved
@Denitz
Copy link
Contributor Author

Denitz commented Jun 4, 2022

Is this backwards compatible?

@brianteeman Yes, it only adds the new functionality. I can add the same code in Joomla 3 but won't be accepted :)

@richard67
Copy link
Member

@Denitz New functionality should go into 4.2, if backwards compatible. So this PR should be rebased to the 4.2-dev branch. Let us know if you need help with that.

After rebase, the PR might show unrelated changes on GitHub, but that will go away after the next update of the 4.2-dev branch with the latest changes on the 4.1-dev branch (so-called "upmerge") and after that an update of your branch for this PR to the latest 4.2-dev here.

roland-d and others added 5 commits June 4, 2022 16:50
* Make sure a value is passed to base64_decode

Signed-off-by: Roland Dalmulder <contact@rolandd.com>

* Also check if we have a redirect URL before checking it is internal

Signed-off-by: Roland Dalmulder <contact@rolandd.com>
roland-d and others added 7 commits June 4, 2022 16:54
* Make sure a value is passed to base64_decode

Signed-off-by: Roland Dalmulder <contact@rolandd.com>

* Also check if we have a redirect URL before checking it is internal

Signed-off-by: Roland Dalmulder <contact@rolandd.com>
@Denitz Denitz changed the base branch from 4.1-dev to 4.2-dev June 4, 2022 13:58
Denitz and others added 3 commits June 7, 2022 12:40
Co-authored-by: Richard Fath <richard67@users.noreply.github.com>
Co-authored-by: Richard Fath <richard67@users.noreply.github.com>
libraries/src/Event/Model/AfterGetListEvent.php Outdated Show resolved Hide resolved
libraries/src/Event/Model/ListQueryEvent.php Outdated Show resolved Hide resolved
libraries/src/MVC/Model/ListModel.php Outdated Show resolved Hide resolved
libraries/src/MVC/Model/ListModel.php Outdated Show resolved Hide resolved
libraries/src/MVC/Model/ListModel.php Outdated Show resolved Hide resolved
libraries/src/MVC/Model/ListModel.php Outdated Show resolved Hide resolved
Denitz and others added 7 commits June 13, 2022 09:41
Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com>
Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com>
Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com>
Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com>
Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com>
Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com>
@HLeithner
Copy link
Member

There is a reason why we don't have a listquery event because it creates more then it solves. This has discussed several times.

Also the modification of the result is questionable. Because we easily generate more problems then expected.

Copy link
Member

@HLeithner HLeithner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the new Events for query manipulation, this has been discussed several times for more information look at #26179

@Denitz
Copy link
Contributor Author

Denitz commented Jun 14, 2022

Please remove the new Events for query manipulation, this has been discussed several times for more information look at #26179

Sorry and thanks for your time. The query manipulation was the main feature of this PR.

@Denitz Denitz closed this Jun 14, 2022
@laoneo
Copy link
Member

laoneo commented Jun 14, 2022

Would you mind to open a new pr which removes the hard codec class paths?

@Denitz
Copy link
Contributor Author

Denitz commented Jun 15, 2022

I removed onContentListQuery event, though I totally disagree.

@Denitz Denitz reopened this Jun 15, 2022
@joomla-bot
Copy link
Contributor

This pull requests has been automatically converted to the PSR-12 coding standard.

@Denitz Denitz closed this Jul 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet