Publication Time (from date/to date): How to best do that?

  • I would like to extend a theme, so I can add a publication date (from date / to date, perhaps each with a time) during which a page will be published. A number of questions:

    1. Is that best done with an extension or a theme? If it can be done with an extension, how would that work in broader terms?
    2. Doing it within a theme should be fairly straight forward:
      1. Include publication dates as attributes per page in index.php
      2. Include these attributes in a tab for the pages, so the user can set them (and preset them to publish from 1/1/1970 to eternity)
      3. In template.php, include the publication attribute and display "this page is not longer available" if outside the publication date. Or could I throw a 404 and if so, how would I do that best?
      4. Adjust the menu.php to only show currently displayed pages.
      5. Anything else?

    Thanks for any input from your end.

  • Mercator

    Changed the title of the thread from “Publication Time (fromn date/to date): How to best do that?” to “Publication Time (from date/to date): How to best do that?”.
  • Hey there,


    In the original Blog extension is this function already implemented, in best case i would say when you plan to do something like this as well for static pages then it should work pretty similar to the function in the blog. I don't know unfortinately if it would be possible to override such function for alle templates through an extension.


    Template modification would be possible for sure as you mentioned already


    Regards,


    Fossy

  • Thanks, Fossy, speedy as usual. I will give it a try shortly.

  • You could listen to the the database event model.node.init. Then you got I think two options:


    First check if your node for your publish requirement, then

    1. try unset($node)
    2. otherwise set something like $node->data('show', false) & check for it in the menu render for hiding it
      (but this does actually not remove the node, so you could still view it, if you know the slug or id)



    Defined here:

    PHP: pagekit/app/modules/database/src/Events.php
    1. /**
    2. * This event occurs after an entity is loaded.
    3. *
    4. * @var string
    5. */
    6. const INIT = 'init';

    Gets called here:

    Gets used once in pagekit source code:

    PHP: pagekit/app/system/modules/site/src/Event/NodesListener.php
    1. public function onNodeInit($event, $node)
    2. {
    3. if ('link' === $node->type && $node->get('redirect')) {
    4. $node->link = $node->path;
    5. }
    6. }

    The LORD is my strength and my shield; in him my heart trusts, and I am helped; my heart exults, and with my song I give thanks to him. Psalm 28,7

  • Thanks, SAB. So, you opt for an extension. Wouldn't I then have to change the Pagekit core to add the two attributes (publish from/to) and wouldn't I then not also have to touch the themes to get it integrated?

  • The two attributes you can create with another tab via a vue compoenent in the node settings (same approach as in a theme). The default config can be added within your index.php with the node index.

    If it is possible to simple unset single nodes when listening to the node init event, then you are not forced to overwrite a template, so you'll write just a very simple extension.

    The LORD is my strength and my shield; in him my heart trusts, and I am helped; my heart exults, and with my song I give thanks to him. Psalm 28,7