Jump to content

HelperFieldLinks - field and template edit shortcuts


Soma
 Share

Recommended Posts

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

post-1337-132614278962_thumb.png

  • Like 7
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...
  • 8 months later...

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 .

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 3 months later...

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. :)

  • Like 1
Link to comment
Share on other sites

@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!

Link to comment
Share on other sites

  • 4 months later...
  • 9 months later...

Just pushed an update to 1.0.5 to fix issues once again (!)

- updated to account for current new development on admin theme 

- some optimizations

- kinda fixed an issue with the new LanguageFieldsTabs. - It was getting overlayed by the tabs. Also the LanguageFieldTabs alters the field content via JS and appends the tabs, which results in my Helper links being at the top instead at the bottom! Annoying and not possible to fix from my side, but if LanguageFieldTabs.js would prepend() the tabs instead of append() it would be better. I don't see an easy way to account for this issue from my side, maybe someone has an good idea. - but for now it's on top of those fields using language tabs.

- added new feature to toggle a layer when clicking on the little gear icon, with some infos on the field settings, which can be useful when developing without going to the field editing screen.

post-100-0-21034800-1385150200_thumb.png

post-100-0-77815400-1385150210_thumb.png

There maybe still issues in some cases I haven't tested or thought of.

Thanks

  • Like 2
Link to comment
Share on other sites

Thanks Martijn. I can't see that notice here, I guess php version matters? Somehow the $value in some cases is still an array and my lazy method to get and render the settings may not account for all possible settings there is for different fields. I'm not sure it is gone now that some changes were made.

I pushed another update to 1.0.6

- added settings toggle support for template field 

- there's even more settings being shown now for fields

Thanks

Link to comment
Share on other sites

The notices comes from the all the 'roles' arrays. I don't see them anywhere in the helper text (weird that they're bugging me). 

These are: editRoles, addRoles, createRoles & roles.

I changed the line 156 to this prevents the notices.

if(is_array($data_value)) $data_value = implode(" ", $data_value);
$settings_str .= "<h1>$data_key:</h1> $data_value<br/>";
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...