Jump to content
adrian

Admin Actions

Recommended Posts

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

  • Like 1

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

  • Like 1

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
On 3/21/2017 at 7:25 AM, 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 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.

  • Like 1

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.

  • Like 1

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.

  • Like 2

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.

  • Like 2

Share this post


Link to post
Share on other sites

When I click on any of the actions in the list I get this:

Quote

Fatal Error

Call to undefined function token_get_all() search►

Source file

File: .../ProcessAdminActions/ProcessAdminActions.module:558



 
548: } 549: 550: 551: private function getActionName($className) { 552: return preg_replace('/(?<=\\w)(?=[A-Z])/'," $1", $className); 553: } 554: 555: 556: private function getFunctionCode($source, $functionName) { 557: 558: $tokens = token_get_all(file_get_contents($source)); 559: 560: for($i=0,$z=count($tokens); $i<$z; $i++) 561: if(is_array($tokens[$i]) 562: && $tokens[$i][0] == T_FUNCTION

Anyone know why

Share this post


Link to post
Share on other sites

@hellomoto - sorry you are having trouble. I honestly don't understand what you are seeing there. It doesn't seem like an error message. How/where is this appearing? Could you maybe send a screenshot of it?

What version of ProcessWire and PHP are you running?

Share this post


Link to post
Share on other sites

I've just pushed a new version of the Create Users Batcher which adds proper CSV parsing (so you can have commas, quotes, spaces etc in other user fields) - thanks to @Rudy for noting this deficiency.

I have also added the option to use JSON instead of CSV in case that is easier for your needs.

Creation now also supports image fields so you can use a URL to an image to have that added to the user's page.

  • Like 5

Share this post


Link to post
Share on other sites
On 8/28/2017 at 5:53 PM, adrian said:

adds proper CSV parsing (so you can have commas, quotes, spaces etc in other user fields)

And today it worked for me flawlessly! A big thanks for this (and for all the other countless goodies you've shared with us....).

Just one question though, your note in the Role's block reads:
At least one of these roles must have the "profile-edit" permission so that the user can change their password the first time they log in.

The permission profile-edit is not needed if my client does not want users to change their passwords, right? At least for the time being users should not change their passwords, it is a feature we want to add later.

Edited by szabesz
fix
  • Like 1

Share this post


Link to post
Share on other sites
4 minutes ago, szabesz said:

And today it worked for me flawlessly! A big thanks for this (and for all the other countless goodies you've shared with us....).

Just one question though, your note in the Role's block reads:
At least one of these roles must have the "profile-edit" permission so that the user can change their password the first time they log in.

The permission profile-edit is not needed if my client does not want users to change their passwords, right? At least for the time being users should not change their passwords, it is a feature we want to add later.

Glad it worked so well for you!

The profile-edit permission I guess is not critical if you don't have the "Password Force Change" module installed, or if you are not relying on the "Email New User" module to automatically generate the user passwords. The thinking here is that you probably don't (or shouldn't) know the passwords of the users, so you use EmailNewUser to generate a password, but then you want to ensure they change it quickly because the password was included in an email (hence the use of PasswordForceChange). And to be able to change their password on first login, they need to be able to edit their profile.

I guess that wording needs to change to explain things better.

Any thoughts?

  • Like 1

Share this post


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

I guess that wording needs to change to explain things better.

I agree, this could be improved a bit, otherwise from the security standpoint you are – of course – right.

However, currently I need to "import" old users with passwords of the previous "old" site and their role does not let them do anything in the admin, they only have access to a custom "download page" to download some "semi sensitive" docs. This will change in the future and that is when the site will need "proper" user management.

Edited by szabesz
typo
  • Like 1

Share this post


Link to post
Share on other sites
18 hours ago, adrian said:

Taken care of with this commit:

Thanks @adrian :) 

Yesterday I actually "only" did some preliminary tests with around 50 users. It worked well but today I had to do the "real thing". I found that it was only about 33 users I could always create without timeout, more than that sometimes worked sometimes not. Since I had to deal with only about 150 users, I created them in groups of 33 or so, as I did not want to waste time with dealing with the timeout.

My other issue was that I had to deal with duplicate user names. The batcher – in such a case – fails with mysql error (...Duplicate entry 'super_duplex_user' for key 'name_parent_id'...) which is not too elegant :) I cleaned up the CSV to tackle this but was wondering if the script could look for them in advance? Is that out of the scope of this action?

Edited by szabesz
typo, missing chars and such
  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      Repeater Images
      Adds options to modify Repeater fields to make them convenient for "page-per-image" usage. Using a page-per-image approach allows for additional fields to be associated with each image, to record things such as photographer, date, license, links, etc.
      When Repeater Images is enabled for a Repeater field the module changes the appearance of the Repeater inputfield to be similar (but not identical) to an Images field. The collapsed view shows a thumbnail for each Repeater item, and items can be expanded for field editing.
      Screencast

      Installation
      Install the Repeater Images module.
      Setup
      Create an image field to use in the Repeater field. Recommended settings for the image field are "Maximum files allowed" set to 1 and "Formatted value" set to "Single item (null if empty)". Create a Repeater field. Add the image field to the Repeater. If you want additional fields in the Repeater create and add these also. Repeater Images configuration
      Tick the "Activate Repeater Images for this Repeater field" checkbox. In the "Image field within Repeater" dropdown select the single image field. You must save the Repeater field settings to see any newly added Image fields in the dropdown. Adjust the image thumbnail height if you want (unlike the core Images field there is no slider to change thumbnail height within Page Edit). Note: the depth option for Repeater fields is not compatible with the Repeater Images module.
      Image uploads feature
      There is a checkbox to activate image uploads. This feature allows users to quickly and easily add images to the Repeater Images field by uploading them to an adjacent "upload" field.
      To use this feature you must add the image field selected in the Repeater Images config to the template of the page containing the Repeater Images field - immediately above or below the Repeater Images field would be a good position.
      It's recommended to set the label for this field in template context to "Upload images" or similar, and set the visibility of the field to "Closed" so that it takes up less room when it's not being used. Note that when you drag images to a closed Images field it will automatically open. You don't need to worry about the "Maximum files allowed" setting because the Repeater Images module overrides this for the upload field.
      New Repeater items will be created from the images uploaded to the upload field when the page is saved. The user can add descriptions and tags to the images while they are still in the upload field and these will be retained in the Repeater items. Images are automatically deleted from the upload field when the page is saved.
      Tips
      The "Use accordion mode?" option in the Repeater field settings is useful for keeping the inputfield compact, with only one image item open for editing at a time. The "Repeater item labels" setting determines what is shown in the thumbnail overlay on hover. Example for an image field named "image": {image.basename} ({image.width}x{image.height})  
      https://github.com/Toutouwai/RepeaterImages
      https://modules.processwire.com/modules/repeater-images/
    • By EyeDentify
      Hello There Guys.

      I am in the process of getting into making my first modules for PW and i had a question for you PHP and PW gurus in here.

      I was wondering how i could use an external library, lets say TwitterOAuth in my PW module.
      Link to library
      https://twitteroauth.com/

      Would the code below be correct or how would i go about this:
      <?PHP namespace ProcessWire; /* load the TwitterOAuth library from my Module folder */ require "twitteroauth/autoload.php"; use Abraham\TwitterOAuth\TwitterOAuth; class EyeTwitter extends WireData,TwitterOAuth implements Module { /* vars */ protected $twConnection; /* extend parent TwitterOAuth contructor $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret); */ public function myTwitterConnection ($consumer_key, $consumer_secret, $access_token, $access_token_secret) { /* save the connection for use later */ $this->twConnection = TwitterOAuth::__construct($consumer_key, $consumer_secret, $access_token, $access_token_secret); } } ?> Am i on the right trail here or i am barking up the wrong tree?
      I don´t need a complete solution, i just wonder if i am including the external library the right way.
      If not, then give me a few hint´s and i will figure it out.

      Thanks a bunch.

      /EyeDentify
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version (has been tested up to v3.3), add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "http://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


    • By kongondo
      FieldtypeRuntimeMarkup and InputfieldRuntimeMarkup
       
      Modules Directory: http://modules.processwire.com/modules/fieldtype-runtime-markup/
      GitHub: https://github.com/kongondo/FieldtypeRuntimeMarkup
      As of 11 May 2019 ProcessWire versions earlier than 3.x are not supported
      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
       

×
×
  • Create New...