Skip to content
This repository has been archived by the owner on Apr 21, 2021. It is now read-only.

Added newsListCountItems & newsListFetchItems hooks #432

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/extensions/hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ custom functionality to the core.
- [loadFormField](loadFormField.md)
- [loadLanguageFile](loadLanguageFile.md)
- [modifyFrontendPage](modifyFrontendPage.md)
- newsListCountItems
- newsListFetchItems
- [newsListCountItems](newsListCountItems.md)
- [newsListFetchItems](newsListFetchItems.md)
- [outputBackendTemplate](outputBackendTemplate.md)
- [outputFrontendTemplate](outputFrontendTemplate.md)
- [parseArticles](parseArticles.md)
Expand Down
62 changes: 62 additions & 0 deletions api/extensions/hooks/newsListCountItems.md
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.
Copy link
Member

Choose a reason for hiding this comment

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

containing news archive IDs.

Copy link
Author

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.

Copy link
Member

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 :)

Copy link
Member

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?

Copy link
Author

@sebj54 sebj54 Nov 9, 2016

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).

Copy link
Member

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?


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
Copy link
Member

Choose a reason for hiding this comment

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

This is not exactly true. Returning null or false will have the same result, the foreach loop will continue to call the next hook. Only returning an integer value will return a result.

Copy link
Author

Choose a reason for hiding this comment

The 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 continue as exit.

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.
71 changes: 71 additions & 0 deletions api/extensions/hooks/newsListFetchItems.md
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).