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

Add template method to assign block arrays

    Details

    • Type: Improvement
    • Status: Unverified Fix
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.1.0-dev
    • Fix Version/s: 3.1.0-b1
    • Component/s: Template Engine
    • Labels:
      None

      Description

      Currently assign_block_vars() is used to assign block template loops which requires to be called within foreach/for/etc loop to assign the whole block, like that:

      foreach ($block_arrays as $block_array)
      {
      	$template->assign_block_vars('blockname', array(
      		'TOKEN_1' => $block_array[0],
      		'TOKEN_2' => $block_array[1],
      		'TOKEN_3' => $block_array[2],
      	));
      }
      

      This makes it hard to change the data assigned to the template loop when it come to extensions, because you either have to create event within the PHP loop to add/change $block_array key=>value pairs, or to use tricks with alter_block_array() construction which is not even possible within event.

      The suggestion is to add one more (wrapper) template method which can take the whole 2-dimensional $block_arrays array as a parameter, which (the array) can be passed to event before being assigned to template block loop, like following:

      extract($phpbb_dispatcher->trigger_event('core.modify_template_block_vars', compact('$block_arrays')));
      $template->assign_block_vars_array('blockname', $block_arrays);
      

      The wrapper function itself would be looking like that:

      	public function assign_block_vars_array($blockname, array $block_vars_array)
      	{
      		foreach($block_vars_array as $vararray)
      		{
      			$this->assign_block_vars($blockname, $vararray);
      		}
      		return true;
      	}
      

      This can make the core a little bit more expendable from the point of developing extensions.

        Activity

        Hide
        nickvergessen Joas Schilling added a comment -

        But your event will be triggered on any page call, for every loop we have. And you only get the array with data to identify what to do with it.
        I don't think its helpful. We should just add events to allow modifying the arrays before we set them.

        Show
        nickvergessen Joas Schilling added a comment - But your event will be triggered on any page call, for every loop we have. And you only get the array with data to identify what to do with it. I don't think its helpful. We should just add events to allow modifying the arrays before we set them.
        Hide
        rxu Ruslan Uzdenov added a comment -

        Not really. For example, look at the existing core.display_forums_modify_template_vars event, where we have 'forumrow.subforum' block loop assignment after the event occured (by the way, to assign the block foreach ($subforums_list as $subforum) call is duplicated there).

        Show
        rxu Ruslan Uzdenov added a comment - Not really. For example, look at the existing core.display_forums_modify_template_vars event, where we have 'forumrow.subforum' block loop assignment after the event occured (by the way, to assign the block foreach ($subforums_list as $subforum) call is duplicated there).
        Hide
        nickvergessen Joas Schilling added a comment -

        Just add subforums_list to that event, so it can be modified aswell?

        I hope you understand the problem, I could be calling all this code on a page of my extension anywhere else. You have no clue where my event trigger is coming from.

        Show
        nickvergessen Joas Schilling added a comment - Just add subforums_list to that event, so it can be modified aswell? I hope you understand the problem, I could be calling all this code on a page of my extension anywhere else. You have no clue where my event trigger is coming from.
        Hide
        rxu Ruslan Uzdenov added a comment -

        This is not about altering $subforum_list itself but alter template variables assigned, I hope you understand the difference.

        I could be calling all this code on a page of my extension anywhere else. You have no clue where my event trigger is coming from.

        Actually I didn't get the point, sorry. Could you be more specific in this?

        Show
        rxu Ruslan Uzdenov added a comment - This is not about altering $subforum_list itself but alter template variables assigned, I hope you understand the difference. I could be calling all this code on a page of my extension anywhere else. You have no clue where my event trigger is coming from. Actually I didn't get the point, sorry. Could you be more specific in this?

          People

          • Assignee:
            nickvergessen Joas Schilling
            Reporter:
            rxu Ruslan Uzdenov
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development