This repository has been archived by the owner on Apr 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Added newsListCountItems & newsListFetchItems hooks #432
Open
sebj54
wants to merge
1
commit into
contao:main
Choose a base branch
from
medialta:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# newsListCountItems | ||
|
||
The `newsListCountItems` hook is triggered when the number of news items is | ||
needed (before fetching a news list). | ||
|
||
> #### primary:: Available | ||
> from Contao 3.5.0. | ||
|
||
|
||
## Parameters | ||
|
||
1. *array* `$newsArchives` | ||
|
||
An array containing news archives IDs. | ||
|
||
2. *boolean* `$blnFeatured` | ||
|
||
A boolean that indicates if the news list must display featured news. | ||
Possible values are: | ||
- `null` (display all news) | ||
- `true` (display only featured news) | ||
- `false` (display all news that are not featured) | ||
|
||
3. *ModuleNewsList* `$newsListModule` | ||
|
||
The news list module that was used to fetch items. | ||
|
||
|
||
## Return Values | ||
Return an `integer`, `null` or `false`. If you return an integer, this news | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not exactly true. Returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right. I don't know why I wrote this. Maybe I read |
||
list count will be used in the module. If you return `false`, other | ||
`newsListCountItems` modules will be called. And if you return `null`, the | ||
default news list count will be used in the module. | ||
|
||
## Example | ||
|
||
```php | ||
<?php | ||
|
||
// config.php | ||
$GLOBALS['TL_HOOKS']['newsListCountItems'][] = array('MyClass', 'myNewsListCountItems'); | ||
|
||
// MyClass.php | ||
public function myNewsListCountItems($newsArchives, $blnFeatured, ModuleNewsList $newsListModule) | ||
{ | ||
// Do something | ||
} | ||
``` | ||
|
||
|
||
## More information | ||
|
||
|
||
### References | ||
|
||
- [system/modules/core/modules/ModuleNewsList.php](https://github.com/contao/core/blob/3.5.17/system/modules/news/modules/ModuleNewsList.php#L170) | ||
|
||
|
||
### See also | ||
|
||
- [newsListFetchItems](newsListFetchItems.md) - triggered when news list items | ||
are fetched from database. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# newsListFetchItems | ||
|
||
The `newsListFetchItems` hook is triggered when news list items are fetched | ||
from database. | ||
|
||
> #### primary:: Available | ||
> from Contao 3.5.0. | ||
|
||
|
||
## Parameters | ||
|
||
1. *array* `$newsArchives` | ||
|
||
An array containing news archives IDs. | ||
|
||
2. *boolean* `$blnFeatured` | ||
|
||
A boolean that indicates if the news list must display featured news. | ||
Possible values are: | ||
- `null` (display all news) | ||
- `true` (display only featured news) | ||
- `false` (display all news that are not featured) | ||
|
||
3. *int* `$limit` | ||
|
||
Number of items that should be displayed. | ||
|
||
4. *int* `$offset` | ||
|
||
Offset of items to skip. | ||
|
||
5. *ModuleNewsList* `$newsListModule` | ||
|
||
The news list module that was used to fetch items. | ||
|
||
|
||
## Return Values | ||
Return a news collection (`\Model\Collection`), `null` or `false`. If you | ||
return a collection, this collection will be used in the news list module. If | ||
you return `false`, other `newsListFetchItems` modules will be called. And if | ||
you return `null`, the default news list items will be used in the module. | ||
|
||
|
||
## Example | ||
|
||
```php | ||
<?php | ||
|
||
// config.php | ||
$GLOBALS['TL_HOOKS']['newsListFetchItems'][] = array('MyClass', 'myNewsListFetchItems'); | ||
|
||
// MyClass.php | ||
public function myNewsListFetchItems($newsArchives, $blnFeatured, $limit, $offset, \ModuleNewsList $newsListModule) | ||
{ | ||
// Do something | ||
} | ||
``` | ||
|
||
|
||
## More information | ||
|
||
|
||
### References | ||
|
||
- [system/modules/core/modules/ModuleNewsList.php](https://github.com/contao/core/blob/3.5.17/system/modules/news/modules/ModuleNewsList.php#L203) | ||
|
||
|
||
### See also | ||
|
||
- [newsListCountItems](newsListCountItems.md) - triggered when the number of | ||
news items is needed (before fetching a news list). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some difficulties with english, so I'm going to trust you on this. To be clear, it means several IDs of several archive(s)?
Is it invariable ? I can't find it on the web.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @sebj54, the array contains all ids of the news archives you've chosen in the back end. So the wording "An array containing the news archive IDs chosen in the front end module settings" would actually be the best :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a little example. You would say coffee tables and not coffees tables, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Toflar I agree with you, the description should be more explicit, I'll make a commit with your suggestion.
@aschempp To be honest, you are really making me doubt about it! Your example doesn't look similar for me because there could several tables for a single coffee, no?
Let's take a human nose for the example (because a human has only one nose like the archive has only one ID).
So, I would say humans noses instead of human noses...
You're starting to loose me at this point, I really should revise English, especially possesive.
To finish, I know you aren't here to teach me English but I really don't understand why news archives is right when news archives IDs is not (thank you for your patience).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest I don't know english rules, I'm a learning by doing type and news archives IDs just sounds wrong to me. Regarding news archives, thats just because news is both singular and plural. I would say calendar archives and not calendars archives.
Maybe a native speaker like @blairwinans could shed some light?