adrian

Admin Actions

65 posts in this topic

Small update that:

1) lets you add:

protected $noBackup = true;

to your action class to prevent backups (either automatic or from showing the option to backup). This is handy if your action doesn't do any DB writing in which case a backup isn't relevant.

2) lets you populate:

$this->output = 'Content for output';

to your executeAction() method. Whatever content is in this will be returned before $this->successMessage and won't be formatted with the green background. This is useful if your action queries and displays info.

Hope you guys find these useful.

 

PS - still waiting on the first PR for a user contributed action :)

1 person likes this

Share this post


Link to post
Share on other sites

EDIT: Solved this by myself, see bottom of the post.

Hi @adrian First of all, this is a really great and useful module. I want to submit the id of a page to my custom module, but I don´t want to show up the id as a field that is being shown. Right now I call the module via 

admin-actions/options?action=BewerbungsunterlagenAnfordern&id=1514

And this is my defineOptions function

        protected function defineOptions()
        {
            $missingFiles = array();
            foreach ($this->pages->get("/unterlagentypen")->children as $unterlage) {
                $missingFiles[$unterlage->id] = $unterlage->title();
            }


            return array(
                array(
                    'name' => 'missingFiles',
                    'label' => 'Fehlende Unterlagen',
                    'description' => 'Wählen Sie aus, welche Unterlagen noch benötigt werden.',
//                    'notes' => 'Only use one of "Pages" or "User Roles"',
                    'type' => 'AsmSelect',
                    'options' => $missingFiles,
                    'required' => true,
//                    'requiredIf' => 'pages=""'
                ),
                array(
                    'name' => 'id',
                    'label' => 'ID der Bewerbung',
                    'description' => 'Bitte den Inhalt dieses Feldes nicht ändern.',
                    'type' => 'Text',
                    'required' => true,
                ),

            );

        }

How can I hide the ID Field?

Just set the type to "hidden" and Voilá :)

1 person likes this

Share this post


Link to post
Share on other sites

Hi @jmartsch - glad you figured out the hidden type and glad you are finding the module useful :)

Share this post


Link to post
Share on other sites

@adrian Hi Adrian,

here are two thoughts how to improve this great module.
Remove the "<p>The '.$actionName.' action was completed successfully.</p>" in line 250 or only print it, if no custom successMessage was set.
Because one may only want to display his own messages.
Use ProcessWires $this->message or $this->error function instead of an own messaging function, so it has the "native" ProcessWire behaviour that people are used to
 

Share this post


Link to post
Share on other sites

Hi @jmartsch - good idea - I have changed it so that message is only displayed if there is no custom message defined.

As for using $this->message or $this->error - I don't see any reason why you can't already use those if you prefer - please test and let me know. The reason I went with the other approach is to allow for a larger and more obvious response than the standard PW message/error interface provides.

If you need any additional tweaks on this front, please detail them out for me. I didn't spend a lot of time on this part of the module because it was initially designed for superuser use, although I am myself starting to make actions available to other roles, so I would like to improve this experience.

Cheers,
Adrian

Share this post


Link to post
Share on other sites

@adrian Your addition with the permission "admin-actions-hide-menu" hides the menuitem for the specific role/user, but it also disables the access to the module for this user group. I logged out and in again. If I remove the permission for the role, I can access the module.

Share this post


Link to post
Share on other sites

@adrian It would be nice if you add an option to hide the "Action Code" fieldset. Maybe make it only visible to superusers. But I think an option to hide it for all users would be better.

EDIT: Because it really is not important and irritating to normal users when this is being shown.

Share this post


Link to post
Share on other sites
5 hours ago, jmartsch said:

@adrian Your addition with the permission "admin-actions-hide-menu" hides the menuitem for the specific role/user, but it also disables the access to the module for this user group. I logged out and in again. If I remove the permission for the role, I can access the module.

Ah, you're right - sorry about that - shouldn't do things in a rush. I think I am going to remove that option from the module completely. I'll see if I can find some time to answer the issue of hiding menu items another way in your other thread.

3 hours ago, jmartsch said:

@adrian It would be nice if you add an option to hide the "Action Code" fieldset. Maybe make it only visible to superusers. But I think an option to hide it for all users would be better.

EDIT: Because it really is not important and irritating to normal users when this is being shown.

It is only visible for superusers - is it still an issue for you knowing that?

Share this post


Link to post
Share on other sites
2 minutes ago, adrian said:

Ah, you're right - sorry about that - shouldn't do things in a rush. I think I am going to remove that option from the module completely. I'll see if I can find some time to answer the issue of hiding menu items another way in your other thread.

It is only visible for superusers - is it still an issue for you knowing that?

It would be nice to hide it from superusers as well, because superuser != programmer/developer

Share this post


Link to post
Share on other sites
59 minutes ago, jmartsch said:

It would be nice to hide it from superusers as well, because superuser != programmer/developer

Ok, there is now a new config option that needs to be checked to show the action code. 

 

On an unrelated note, I also revamped the revamped the recent $noBackup option. This is a breaking change, but now you can set:

protected $dbBackup = 'automatic' (or 'optional', or 'disabled') 

in your custom actions to override the default behavior as defined in the module config settings.

Hopefully this will be a helpful change.

1 person likes this

Share this post


Link to post
Share on other sites

@adrian just asking... I am in the process of migrating 10+ websites to processwire and exporting and importing content works great so far, but in some fields old Smarty calls are present and I want to search and replace it with new Hannacode.

Unfortunately most of the affected content is in Profields Textareas and the admin action SearchAndReplace doesn't work there. All content is deleted...

Should it work in textareas or do you know of any quick fix ;) or snippet?

(BTW too many pages to it by hand)

Share this post


Link to post
Share on other sites
2 hours ago, Klenkes said:

@adrian just asking... I am in the process of migrating 10+ websites to processwire and exporting and importing content works great so far, but in some fields old Smarty calls are present and I want to search and replace it with new Hannacode.

Unfortunately most of the affected content is in Profields Textareas and the admin action SearchAndReplace doesn't work there. All content is deleted...

Should it work in textareas or do you know of any quick fix ;) or snippet?

(BTW too many pages to it by hand)

It shouldn't be hard to support. When I set this action up I limited it to text and textarea fields, but it makes sense to expand to others - I just didn't have time to test it then. I'll see what I can do tomorrow to get this working for you.

1 person likes this

Share this post


Link to post
Share on other sites

Thanks, but no need to work witout pay on a sunday...

Share this post


Link to post
Share on other sites
4 hours ago, Klenkes said:

Thanks, but no need to work witout pay on a sunday...

No problem - I'm used to it :)

I am away next week, so it's now or not for a while. I have committed a quick update that should take care of Profields Textareas. Please let me know if you have any problems.

I really need to revisit this action and add support for other field types as well - for example I haven't tested inside repeaters or page tables. I'll add this to my list, but might be a while.

2 people like this

Share this post


Link to post
Share on other sites

Holy __insert-term-of-choice__  

This works absolutely great! I replaced stuff on hundreds of pages with textareas of type text and teatareas with CKE and didn't encouter one error!
Without BCE and the replace admin action this whole untertaking of migrating to PW wouldn't work at all!

I can't thank you enough.

2 people like this

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By bernhard
      Hi,
      just stumbled over a little module that i built for my last project. it helped me to test performance of my rockdatatables module to generate 3000 random json datasets and i want to share it with you. maybe it saves some time for someone.
      https://gitlab.com/baumrock/RockDummyData/
      easy example:
      $rdd = $modules->get('RockDummyData'); for($i=0; $i<15; $i++) { // this has to be inside the for-loop to always get a new dummy $dummy = $rdd->getDummy(); echo date("d.m.Y H:i:s", $dummy->timestamp) . "<br>"; } more advanced:
      $json = new stdClass(); $json->data = array(); $rdd = $modules->get('RockDummyData'); for($i=0; $i<3000; $i++) { // this has to be inside the for-loop to always get a new dummy $dummy = $rdd->getDummy(); $obj = new stdClass(); $obj->name = $dummy->forename . ' ' . $dummy->surname; $obj->position = $dummy->job; $obj->office = $dummy->city; $obj->color = $dummy->color; $obj->start_date = new stdClass(); $obj->start_date->display = date('d.m.Y',$dummy->timestamp); $obj->start_date->sort = $dummy->timestamp; $obj->salary = rand(0,10000); $json->data[] = $obj; } echo json_encode($json); you have to store your random datasets on your own into the /data folder. there are several services for creating all kinds of random data on the web - if you know one service that allows sharing those datasets let me know and i can include common needed data into the module
    • By AndySh
      Hello!
      I need your assistance please. I purchased the module FormBuilder. Unfortunately, the module discontinued delivering customer submissions to e-mail box specified in the module settings. Direct mailing to the e-mail box works OK. The module settings stays the same and are correct, like "Send e-mail to administrator(s) is checked. The last version of FormBuilder 3.0 has been installed. Please advise how to resolve the issue becase I cannot get orders from customers anymore (((
    • By kixe
      As described in this post (https://processwire.com/talk/topic/8551-custom-urls-for-pages/?p=82742) the option 'Name Format Children' under the tab 'Family' in template settings doesn't work properly and also not as expected. I had a look inside the code and made some changes which are working properly, which offers much more options, more consistency and less code too.

      The result is the following. You have 3 Options for generating name and title, which could be combined in endless variations.
      Name is always derived from title, same like creating pages manually.
      type date: if function detects # character anywhere in the string, conversion will be: deletion of # and string will be used as format parameter for PHP date() function type field: if string is a fieldname of the parent page the value of this field will be used type string: if string doesn't fit to the 2 preceeding it will be taken as it is All parts (separated by comma) will be composed in the order of setting. You can use unlimited numbers of parts

      I made a pull request on github: https://github.com/ryancramerdesign/ProcessWire/pull/831

      Example screenshots

      Setting ...


      will result in


       
    • By kongondo
      FieldtypeRuntimeMarkup and InputfieldRuntimeMarkup
       
      Modules Directory: http://modules.processwire.com/modules/fieldtype-runtime-markup/
      GitHub: https://github.com/kongondo/FieldtypeRuntimeMarkup
       
      This module allows for custom markup to be dynamically (PHP) generated and output within a page's edit screen (in Admin).
       
      The value for the fieldtype is generated at runtime. No data is saved in the database. The accompanying InputfieldRuntimeMarkup is only used to render/display the markup in the page edit screen.
       
      The field's value is accessible from the ProcessWire API in the frontend like any other field, i.e. it has access to $page and $pages.
       
      The module was commissioned/sponsored by @Valan. Although there's certainly other ways to achieve what this module does, it offers a dynamic and flexible alternative to generating your own markup in a page's edit screen whilst also allowing access to that markup in the frontend. Thanks Valan!
       
      Warning/Consideration
      Although access to ProcessWire's Fields' admin pages is only available to Superusers, this Fieldtype will evaluate and run the custom PHP Code entered and saved in the field's settings (Details tab). Utmost care should therefore be taken in making sure your code does not perform any CRUD operations!! (unless of course that's intentional) The value for this fieldtype is generated at runtime and thus no data is stored in the database. This means that you cannot directly query a RuntimeMarkup field from $pages->find(). Usage and API
       
      Backend
      Enter your custom PHP snippet in the Details tab of your field (it is RECOMMENDED though that you use wireRenderFile() instead. See example below). Your code can be as simple or as complicated as you want as long as in the end you return a value that is not an array or an object or anything other than a string/integer.
       
      FieldtypeRuntimeMarkup has access to $page (the current page being edited/viewed) and $pages. 
       
      A very simple example.
      return 'Hello'; Simple example.
      return $page->title; Simple example with markup.
      return '<h2>' . $page->title . '</h2>'; Another simple example with markup.
      $out = '<h1>hello '; $out .= $page->title; $out .= '</h1>'; return $out; A more advanced example.
      $p = $pages->get('/about-us/')->child('sort=random'); return '<p>' . $p->title . '</p>'; An even more complex example.
      $str =''; if($page->name == 'about-us') { $p = $page->children->last(); $str = "<h2><a href='{$p->url}'>{$p->title}</a></h2>"; } else { $str = "<h2><a href='{$page->url}'>{$page->title}</a></h2>"; } return $str; Rather than type your code directly in the Details tab of the field, it is highly recommended that you placed all your code in an external file and call that file using the core wireRenderFile() method. Taking this approach means you will be able to edit your code in your favourite text editor. It also means you will be able to type more text without having to scroll. Editing the file is also easier than editing the field. To use this approach, simply do:
      return wireRenderFile('name-of-file');// file will be in /site/templates/ If using ProcessWire 3.x, you will need to use namespace as follows:
      return ProcessWire\wireRenderFile('name-of-file'); How to access the value of RuntimeMarkup in the frontend (our field is called 'runtime_markup')
       
      Access the field on the current page (just like any other field)
      echo $page->runtime_markup; Access the field on another page
      echo $pages->get('/about-us/')->runtime_markup; Screenshots
       
      Backend
       

       

       
      Frontend