Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TPL_ACTION_GET event #471

Closed
wants to merge 6 commits into from
Closed

TPL_ACTION_GET event #471

wants to merge 6 commits into from

Conversation

solewniczak
Copy link
Contributor

I've add new event to dokuwiki(TPL_ACTION_GET) which allows you to create own actions to tpl_action function. Together with my previous pull request(#470), you can add own actions to sitetools menu. Example:

class action_plugin_bds extends DokuWiki_Action_Plugin {

    /**
     * Register its handlers with the DokuWiki's event controller
     */
    public function register(Doku_Event_Handler $controller) {
        $controller->register_hook('TEMPLATE_SITETOOLS_DISPLAY', 'BEFORE', $this,
                                   'add_menu_item');
        $controller->register_hook('TPL_ACTION_GET', 'BEFORE', $this,
                                   'add_action');
    }

    public function add_menu_item(&$event, $param) {
        global $lang;
        $lang['btn_bds'] = $this->getLang('bds');
        $event->data['items']['bds'] = tpl_action('bds', 1, 'li', 1);
    }
    public function add_action(&$event, $param) {
        $data = &$event->data;
        if ($data['type'] != 'bds')
            return;

        $event->preventDefault();
    }
}

Szymon Olewniczak added 3 commits December 10, 2013 09:19
… basing on Starter template"

This reverts commit 362a4f0.

Left the code with only TPL_ACTION_GET
@Klap-in
Copy link
Collaborator

Klap-in commented Dec 10, 2013

Does this event name follows the naming structure? see https://www.dokuwiki.org/devel:events_list#naming_structure

TEMPLATE (and PLUGIN as well) are usually written completely, not as shortcut like TPL.

The event data is now assigned as compacted array. When the variables are assigned by reference, the AFTER event can post-process the data set by the default process as well.

@Chris--S
Copy link
Collaborator

I think your handling of $data is incorrect.

  1. changes made to the components which make up $data (e.g. $type, $params) within the 'case' block aren't reflected in the $data passed to the AFTER event.
  2. changes made to the components ... $data are overwritten by the extract() at the end of the function (line 733).

Perhaps, rather than using compact and extract, you should create the $data array using reference assignments.

@splitbrain
Copy link
Collaborator

What @Chris--S says. Also adding your own actions is already possible with implementing TPL_ACT_UNKNOWN and ACTION_ACT_PREPROCESS

@Chris--S
Copy link
Collaborator

Chris--S commented Jan 5, 2014

@splitbrain - i think this allows adding your own action link/button.. The two events you mention are for action handling.

@solewniczak
Copy link
Contributor Author

I've tried to apply your suggestions. What are your opinions about this event now?

@Klap-in
Copy link
Collaborator

Klap-in commented Mar 14, 2014

The tpl_content_core() handles unknown actions in the default case. Now the tpl_get_action() wraps the whole switch case by a event trigger. Is it desired that tpl_get_action() can override defaults?

further I would like to have this in a next release... so when this PR can get some love that would be nice ;)

@Hafron, can you merge the master branch in this branch, there seems to be conflicts.

@splitbrain
Copy link
Collaborator

@Hafron still there? can you merge master please?

@scrutinizer-notifier
Copy link

The inspection completed: 27 new issues

@Klap-in
Copy link
Collaborator

Klap-in commented Jul 31, 2015

Currently tpl_action() can be only used for know actions like show, edit, etc etc
However, this doesn't allow using it for generating other action links e.g. $event->data['items']['bds'] = tpl_action('bds', 1, 'li', 1);

This pull request presents as solution a TPL_ACTION_GET event, which could override also the current behavior. I see no use for this. Because, for example, it let you change the link to edit action to something different, while the edit action keeps existing. Better the event ACTION_ACT_PREPROCESS is used for redefining the action it self, instead of the link.
Or are there cases which justify redefining of the type/id/acceskeys/post-get method/nofollow/params/replacement behaviour?

Alternative is to use TPL_ACTION_UNKNOWN (quite similar to TPL_ACT_UNKNOWN)
Which will wrap the unknown action msg in the default case:

    default:
        return '[unknown %s type]';
        break;

What do you prefer? TPL_ACTION_GET or TPL_ACTION_UNKNOWN

@Klap-in
Copy link
Collaborator

Klap-in commented Jul 31, 2015

Todo: $data['replacement'] = &$replacement is missing

@Klap-in
Copy link
Collaborator

Klap-in commented Jul 31, 2015

Hafron, I come back on my previous suggestion for event name. TPL_ACTION_GET is more consistent with the other events in inc/template.php

Further a mergeable fork can be found in PR 1277

@selfthinker
Copy link
Collaborator

Closing in favour of either #1277 or #1279.

@selfthinker selfthinker closed this Aug 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants