Announcement

  •  » Engine
  •  » make it easy for plugins to add tabs in admin screens

#1 2012-07-11 17:29:23

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13097

make it easy for plugins to add tabs in admin screens

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:

Code:

[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:

Code:

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?


Latest blog post (November 28th 2017) Server failures in october and november 2017

Offline

 

#2 2012-07-11 17:38:02

flop25
Piwigo Team
2006-07-06
6656

Re: make it easy for plugins to add tabs in admin screens

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?


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#3 2012-07-11 17:44:20

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13097

Re: make it easy for plugins to add tabs in admin screens

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 ;-)


Latest blog post (November 28th 2017) Server failures in october and november 2017

Offline

 

#4 2012-07-11 17:45:43

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3270

Re: make it easy for plugins to add tabs in admin screens

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

 

#5 2012-07-11 18:02:20

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13097

Re: make it easy for plugins to add tabs in admin screens

You're right mistic100.

Here is the change I made:

Code:

[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


Latest blog post (November 28th 2017) Server failures in october and november 2017

Offline

 

#6 2012-07-13 16:59:00

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3270

Re: make it easy for plugins to add tabs in admin screens

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

Code:

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

Code:

$tabsheet = new tabsheet('album');
$tabsheet->assign();

3) add in admin.php (or included new file) the declaration of all core tabs, like

Code:

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

Code:

$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

 

#7 2012-07-13 17:06:00

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3270

Re: make it easy for plugins to add tabs in admin screens

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

Code:

$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

 

#8 2012-07-23 10:39:47

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3270

Offline

 

#9 2012-07-23 14:15:45

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3270

Re: make it easy for plugins to add tabs in admin screens

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

 

#10 2012-07-23 14:24:01

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13097

Re: make it easy for plugins to add tabs in admin screens

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.


Uploaded Images


Latest blog post (November 28th 2017) Server failures in october and november 2017

Offline

 

#11 2012-07-27 23:19:25

tanguy2m
Member
2012-07-27
9

Re: make it easy for plugins to add tabs in admin screens

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

 

#12 2012-07-27 23:28:40

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3270

Re: make it easy for plugins to add tabs in admin screens

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

 

#13 2012-07-27 23:43:00

tanguy2m
Member
2012-07-27
9

Re: make it easy for plugins to add tabs in admin screens

Thanks for your answer.
I agree with you, compared to the benefit brought by this new feature, these 2 limitations are negligible.

Offline

 
  •  » Engine
  •  » make it easy for plugins to add tabs in admin screens

Board footer

Powered by FluxBB

github twitter facebook google+ newsletter Donate Piwigo.org © 2002-2018 · Contact