Jump to content


Photo

HelperFieldLinks - field and template edit shortcuts

Module

  • Please log in to reply
17 replies to this topic

#1 Soma

Soma

    Hero Member

  • Moderators
  • 3,218 posts
  • 1765

  • LocationSH, Switzerland

Posted 09 September 2011 - 03:44 AM

HelperFieldLinks

 

Just got a new module working that is only visible to superusers, and is handy for when developing a site, or investigate someone elses.

1. It adds a shortcut link to all fields on page in the backend. The link name equals the field name, so on very large complex sites with lots of fields, it can help to quickly see what name the field has.

2. It also adds a shortcut to the used template (in the template select field under "Settings" tab). They appear on bottom right corner of the field.

Any suggestions for a better module name and general feedback is welcome.

ProcessWire Modules Directory: http://modules.proce...er-field-links/

Direct github download: https://github.com/s...elperFieldLinks

PastedGraphic-2.png


@somartist | modules created | support me, flattr my work flattr.com


#2 ryan

ryan

    Hero Member

  • Administrators
  • 5,792 posts
  • 3128

  • LocationAtlanta, GA

Posted 09 September 2011 - 09:22 AM

Nice module Soma, and great (useful!) idea. I look forward to trying this one out later today.

#3 Soma

Soma

    Hero Member

  • Moderators
  • 3,218 posts
  • 1765

  • LocationSH, Switzerland

Posted 09 September 2011 - 01:33 PM

Thanks Ryan. Got a new version with the gear icon added to make it a little more sexy... :)

@somartist | modules created | support me, flattr my work flattr.com


#4 ryan

ryan

    Hero Member

  • Administrators
  • 5,792 posts
  • 3128

  • LocationAtlanta, GA

Posted 09 September 2011 - 03:24 PM

Soma I tested out here–nice job and congrats on your first second module!

Just a few suggestions:

1. It's not safe to assume that PW admin is at /processwire/. For instance, the one I  tested in is at /mysite/processwire/ (off a subdirectory), and someone else's might be at /admin/ or /my-private-url/ or something like that. As a result, you'll want to replace this:

<a href='/processwire/setup/field/edit?id={$id} ...

with this:

<a href='{$this->config->urls->admin}setup/field/edit?id={$id} ...

And likewise with the templates one.




2. I'm getting double field links with Page reference fields. This is because Inputfield::render actually gets called twice for a Page reference. It's a little different than the other fields since it lets you delegate the input to another Inputfield (like select, select multiple, checkboxes, radios, etc.). So  InputfieldPage::render gets called first, and then the delegate Inputfield gets called second. The result is two of your links appear. As a result, I would suggest preventing this by either keeping a list of field names you've already populated, or just checking if your markup already appears in the output, like:

if(strpos($event->return, 'fieldEditLink')) return;




3. With hooks that get called multiple times, it's more efficient to move the if() before you add the hook, rather than have it within the hook. Or to word it differently, move this:

if($this->process == 'ProcessPageEdit' && $this->user->hasRole('superuser')){

…out of addShortcutLinks(), and into init(). The only problem is that init() gets called before the page is even loaded, so you can't determine if($page->process == 'ProcessPageEdit') yet. However, you can do this:

<?php 

public function init() {
    if(strpos($_SERVER['REQUEST_URI'], $this->config->urls->admin . 'page/edit/?id=') !== false && $this->user->hasRole('superuser')){
        // add stylesheets
        $this->config->styles->add($this->config->urls->HelperFieldLinks . "HelperFieldLinks.css");

        // add a hook after each inputfield is rendered and modify the output
        $this->addHookAfter('Inputfield::render', $this, 'addShortcutLinks');
    } 
}

The advantage of the approach above is that it significantly reduces the number of times your hook is called when it's not needed. There's nothing technically wrong with the way you were doing it before either, so I'm just mentioning this as an efficiency optimization.

Lastly, and perhaps more importantly, move your stylesheet loader into that if() statement as well (like in the code example above). No need to have your stylesheet loading when it's not going to be used.



#5 Soma

Soma

    Hero Member

  • Moderators
  • 3,218 posts
  • 1765

  • LocationSH, Switzerland

Posted 09 September 2011 - 03:44 PM

Thank you Ryan for taking the time to look at it, amazing suggestions with code examples, haven't really considered these things yet! That all makes sense. Thank you a bunch.

But, it's actually my second module  ::)
see here http://processwire.c...opic,435.0.html  ;D

@somartist | modules created | support me, flattr my work flattr.com


#6 Soma

Soma

    Hero Member

  • Moderators
  • 3,218 posts
  • 1765

  • LocationSH, Switzerland

Posted 10 September 2011 - 10:00 AM

Implemented the suggested changes. It's working good so far. Attached new version to first post.

@somartist | modules created | support me, flattr my work flattr.com


#7 ryan

ryan

    Hero Member

  • Administrators
  • 5,792 posts
  • 3128

  • LocationAtlanta, GA

Posted 10 September 2011 - 10:09 AM

Wow that was fast. Thanks for the update. I can't wait till I get back to the office Monday to try out these new modules.

#8 ryan

ryan

    Hero Member

  • Administrators
  • 5,792 posts
  • 3128

  • LocationAtlanta, GA

Posted 12 September 2011 - 08:36 AM

Just tried it out, looks great and works great! Thanks Soma!

#9 Soma

Soma

    Hero Member

  • Moderators
  • 3,218 posts
  • 1765

  • LocationSH, Switzerland

Posted 20 September 2011 - 02:40 PM

Thanks Ryan, glad you like it!

Just wanted to mention, it's on github now:  https://github.com/s...elperFieldLinks

@somartist | modules created | support me, flattr my work flattr.com


#10 Soma

Soma

    Hero Member

  • Moderators
  • 3,218 posts
  • 1765

  • LocationSH, Switzerland

Posted 05 June 2012 - 06:13 PM

I just commited a fix to this module causing some issues with a not well formed span tag. I noticed when I got problems with it adding other markup using hooks to inputfields. I've seen some people using this module so I thought I'd make a note .

@somartist | modules created | support me, flattr my work flattr.com


#11 recyclerobot

recyclerobot

    Newbie

  • Members
  • Pip
  • 9 posts
  • 5

Posted 18 June 2012 - 05:15 AM

Hi Soma, love your plugin, timesaver!
just quick note: the link on the http://processwire.c...wnload/modules/ links to the old forumpost, maybe ryan can update it to the new one so more people can enjoy faster development :)

#12 Soma

Soma

    Hero Member

  • Moderators
  • 3,218 posts
  • 1765

  • LocationSH, Switzerland

Posted 18 June 2012 - 06:10 AM

Thanks recyclerobot!

Just fixed the link, thanks for mention it.

@somartist | modules created | support me, flattr my work flattr.com


#13 alanfluff

alanfluff

    Sr. Member

  • Members
  • PipPipPipPip
  • 405 posts
  • 118

  • LocationOttawa, Canada

Posted 29 September 2012 - 06:21 PM

Thank you very much for this Module Soma! Just seeing the real Field name is often a lovely time-saver :D Thanks!

#14 diogo

diogo

    Hero Member

  • Moderators
  • 2,014 posts
  • 1093

  • LocationPorto, Portugal

Posted 29 September 2012 - 06:34 PM

Somehow I missed this post before... nice module Soma! Thanks!

And thanks Alan for bringing this up again :)

#15 apeisa

apeisa

    Hero Member

  • Moderators
  • 2,530 posts
  • 859

  • LocationVihti, Finland

Posted 30 September 2012 - 02:05 AM

I should really start using this. My current method is to use Chrome's inspector to see the real field name from source html...

#16 Soma

Soma

    Hero Member

  • Moderators
  • 3,218 posts
  • 1765

  • LocationSH, Switzerland

Posted 30 September 2012 - 08:19 AM

I should really start using this. My current method is to use Chrome's inspector to see the real field name from source html...


Wooot? Hehe, this module was one of my first helpers. Couldn't without it and I think it saved me hours already. :)

@somartist | modules created | support me, flattr my work flattr.com


#17 alanfluff

alanfluff

    Sr. Member

  • Members
  • PipPipPipPip
  • 405 posts
  • 118

  • LocationOttawa, Canada

Posted 30 September 2012 - 08:32 AM

@diogo Happy if I accidentally helped :D And I used to be less efficient @apeisa than you, I hadn't realized the field name was in the page and visible in Chrome Inspector and used to go back to the field list all the time, oUCH, so Soma's Module is luxury!

#18 Soma

Soma

    Hero Member

  • Moderators
  • 3,218 posts
  • 1765

  • LocationSH, Switzerland

Posted 31 January 2013 - 06:05 PM

Just updated to 1.0.3 with some fix and new feature.

  • fixed issue with template edit link
  • added support for repeater fields

http://modules.proce...er-field-links/


@somartist | modules created | support me, flattr my work flattr.com






Also tagged with one or more of these keywords: Module

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users