Uploaded image for project: 'phpBB3'
  1. phpBB3
  2. PHPBB3-12391

core.posting_modify_template_vars pass some variables to listeners

    Details

    • Type: Bug
    • Status: Unverified Fix
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.1.0-b2
    • Fix Version/s: 3.1.0-b3
    • Component/s: Events
    • Labels:

      Description

      Originally posted here: https://area51.phpbb.com/phpBB/viewtopic.php?f=111&t=45379

      In posting.php the event dispatcher is called directly triggering the core.posting_modify_template_vars event, but the event doesn't have any data, so it's impossible to modify the template array within the event listener.

      Instead the array should be assigned to a variable and then the event should be triggered with the variable.

      The flow has changed such that the template variables are assigned to an array first, which is then passed to the event listener, ofter that the template array is assigned to the template object.

      Around line 1477 in the beta:
      Replace:

      $template->assign_vars(array( ... ));
      $phpbb_dispatcher->dispatch('core.posting_modify_template_vars');
      

      With:

      $template_array = array(...);
      $vars = array('template_array');
      extract($phpbb_dispatcher->trigger_event('core.posting_modify_template_vars', compact($vars)));
      $template->assign_vars(array( ... ));
      

      Not shown, but if possible please send the current forum and topic info to the event handler. Basically, I need to know what the current forum is, and whether or not the template is displaying a new post form, or edit the first post of a topic (not a reply).

        Activity

        Hide
        nickvergessen Joas Schilling added a comment -

        Instead of the template array, the event should:
        $post_data, $moderators, $mode, $page_title, $s_topic_icons, $form_enctype, $s_action and $s_hidden_fields

        Show
        nickvergessen Joas Schilling added a comment - Instead of the template array, the event should: $post_data, $moderators, $mode, $page_title, $s_topic_icons, $form_enctype, $s_action and $s_hidden_fields
        Hide
        joelk2 joelk2 added a comment -

        That pull request doesn't actually solve our original intent with this issue.

        We need the ability of manipulating (ie. adding) variables to the template array before it is assigned to the template.

        Show
        joelk2 joelk2 added a comment - That pull request doesn't actually solve our original intent with this issue. We need the ability of manipulating (ie. adding) variables to the template array before it is assigned to the template.
        Hide
        aleha aleha added a comment -

        The ability to add variables to the template was not stated in your original description.
        If you wish to add your own variables then you shouldn't need an event to modify them because you will assign the values you want with your extension.
        I think that you need a template event for that.

        Show
        aleha aleha added a comment - The ability to add variables to the template was not stated in your original description. If you wish to add your own variables then you shouldn't need an event to modify them because you will assign the values you want with your extension. I think that you need a template event for that.
        Hide
        joelk2 joelk2 added a comment - - edited

        I mention template variables throughout the description includeding "so it's impossible to modify the template array within the event listener", the event name implies modifying the template variable: "core.posting_modify_template_vars". This event is fired on the edit and post forms, based on the post details I need to set additional variables to the template.

        How else would my template event have access to the variables if they're not set in the posting event?

        Show
        joelk2 joelk2 added a comment - - edited I mention template variables throughout the description includeding "so it's impossible to modify the template array within the event listener", the event name implies modifying the template variable: "core.posting_modify_template_vars". This event is fired on the edit and post forms, based on the post details I need to set additional variables to the template. How else would my template event have access to the variables if they're not set in the posting event?
        Hide
        aleha aleha added a comment -

        Can you please describe in detail what would you like to do? I saw you comment on github but maybe we can continue this on the area51 forums.

        Show
        aleha aleha added a comment - Can you please describe in detail what would you like to do? I saw you comment on github but maybe we can continue this on the area51 forums.
        Hide
        joelk2 joelk2 added a comment -
        Show
        joelk2 joelk2 added a comment - Let's move the discussion to: https://area51.phpbb.com/phpBB/viewtopic.php?f=111&t=45379

          People

          • Assignee:
            nickvergessen Joas Schilling
            Reporter:
            joelk2 joelk2
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development