For [extension by plg] Photo Update, I would like in Piwigo 2.4 to add a new tab on the photo administration screens. Just like [extension by mistic100] SmartAlbums does for the album administration screens.
Instead of using a prefilter like mistic100 does, on my local copy I have added:
[pierrick@vienna] ~/public_html/piwigo/dev/branches/2.4
$ svn diff admin/photo.php
Index: admin/photo.php
===================================================================
--- admin/photo.php (revision 16335)
+++ admin/photo.php (working copy)
@@ -64,6 +64,8 @@
$tabsheet->add('properties', l10n('Properties'), $admin_photo_base_url.'-properties');
$tabsheet->add('coi', l10n('Center of interest'), $admin_photo_base_url.'-coi');
+trigger_action('admin_photo_tabs');
+
$tabsheet->select($page['tab']);
$tabsheet->assign();and then in my plugin, I have:
add_event_handler('admin_photo_tabs', 'photo_update_add_tab');
function photo_update_add_tab()
{
global $page, $template, $tabsheet;
if ($page['page'] != 'photo') return;
$url = get_root_url().'admin.php?page=plugin-photo_update-'.$_GET['image_id'];
$tabsheet->add('update', l10n('Photo Update'), $url);
}Do you think we could do something better? Do I commit for albums too?
Offline
It seems good to extend it to more pages like album
Just a question -sry for the 'HS'-: why such feature are not in core? Do you think it's too particular?
Offline
flop25 wrote:
Just a question -sry for the 'HS'-: why such feature are not in core? Do you think it's too particular?
You're perfectly right. I had planned to add this feature in Piwigo core 2.4, but time was running too fast ;-)
Offline
wouldn't it be better a trigger inside tabsheet class ?
wel if you find how to proceed... I tried before adding my prefilter but can't firgure out
Offline
You're right mistic100.
Here is the change I made:
[pierrick@vienna] ~/public_html/piwigo/dev/branches/2.4
$ svn diff admin/include/tabsheet.class.php
Index: admin/include/tabsheet.class.php
===================================================================
--- admin/include/tabsheet.class.php (revision 16335)
+++ admin/include/tabsheet.class.php (working copy)
@@ -81,6 +81,7 @@
*/
function select($name)
{
+ trigger_action('tabsheet_before_select');
$this->selected = $name;
}and it works fine :-) of course, you have to check you're on the right page when using trigger tabsheet_before_select
Offline
we have investigated a bit to find how to make the tabsheet simplier for plugins (ie: plugins adding tabs on the same tabsheet)
so here is my idea:
1) modify tabsheet to add a id parameter, and a trigger
Index: tabsheet.class.php
===================================================================
--- tabsheet.class.php (revision 16527)
+++ tabsheet.class.php (working copy)
@@ -24,6 +24,7 @@
class tabsheet
{
var $sheets;
+ var $id;
var $name;
var $titlename;
var $selected;
@@ -32,9 +33,10 @@
$name is the tabsheet's name inside the template .tpl file
$titlename in the template is affected by $titlename value
*/
- function tabsheet($name = 'TABSHEET', $titlename = 'TABSHEET_TITLE')
+ function tabsheet($id=null, $name = 'TABSHEET', $titlename = 'TABSHEET_TITLE')
{
$this->sheets = array();
+ $this->id = $id;
$this->name = $name;
$this->titlename = $titlename;
$this->selected = "";
@@ -81,6 +83,7 @@
*/
function select($name)
{
+ $this->sheets = trigger_event('tabsheet_before_select', $this->sheets, $this->id);
$this->selected = $name;
}2) define this id in all core tabsheets, example for album.php
$tabsheet = new tabsheet('album');
$tabsheet->assign();3) add in admin.php (or included new file) the declaration of all core tabs, like
add_event_handler('tabsheet_before_select', 'add_core_tabs', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
function add_core_tabs($sheets, $id)
{
switch ($id)
{
case 'album':
global $admin_album_base_url;
$sheets['properties'] = array('caption'=>l10n('Properties'), 'url'=>$admin_album_base_url.'-properties');
$sheets['sort_order'] = array('caption'=>l10n('Manage photo ranks'), 'url'=>$admin_album_base_url.'-sort_order');
.............................
return $sheets;
}this way plugins can add tabs using the same handler used in the core AND they can easily reproduce core tabsheets in their page with
$tabsheet = new tabsheet('album');
$tabsheet->assign();(allowing to display others plugins tabs with extra tests)
this method is comptaible with "old shcool" tabs, execpt for those who used "$name" and "$titlename" parameters of tabsheet constructor (I think about grum in AMM)
Offline
we could not use step 3, but in this case, if a plugin want to reproduce a tabsheet it will have to use the whole declaration
$tabsheet = new tabsheet("album");
$tabsheet->add('properties', l10n('Properties'), $admin_album_base_url.'-properties');
$tabsheet->add('sort_order', l10n('Manage photo ranks'), $admin_album_base_url.'-sort_order');
$tabsheet->add('permissions', l10n('Permissions'), $admin_album_base_url.'-permissions');
$tabsheet->add('notification', l10n('Notification'), $admin_album_base_url.'-notification');
$tabsheet->select($page['tab']);
$tabsheet->assign();Offline
Offline
as you can see I don't implement the tabsheet id in the constructor, in order to avoid compatibility breaks (with AMM and co)
instead I added a method tabsheet::set_id()
keep in mind that this is only for 2.4, on 2.5 a will modify the constructor as I first planned
the reason I want include this parameter in the custructor is it's more natural and cleaner whay to use the class
Offline
That's perfect so far: I have used the new method on both photo_update + rotate_image. The two plugins are adding a tab on the photo administration page. On the "update" tab I can see the "rotate" tab, that's great, it will really make tab management simpler for plugins.
Offline
Hello all,
It is a huge step-forward compared to pre-filters. Thanks for it.
But I have some remarks:
1.
It is necessary to redefine some constants / variables in plugin's admin.php file.
For example, if I want to add a new tab in admin.php?page=photos_add I have to redefine the constant PHOTOS_ADD_BASE_URL.
In the plugin rotateImage plg redefined $admin_photo_base_url.
It's not a big deal but it creates a dependance between Piwigo core and plugins.
Is it possible to add these vars in tabsheet.class.php ?
2.
When a "plugin tab" is displayed, the "Plugins" category is unfolded on the left.
In the above examples, I was expected to stay in the "Photos" category.
Again, not a big deal, but the integration is less impressive.
Maybe I missed something,
Tanguy
Last edited by tanguy2m (2012-07-27 23:30:42)
Offline
1. perhaps later, this is a light integration as implemented in a minor upgrade
2. that's quite hard i think because it's a totally seperated code which manages the menu
Offline
Thanks for your answer.
I agree with you, compared to the benefit brought by this new feature, these 2 limitations are negligible.
Offline