Jump to content

Search the Community

Showing results for tags 'Hook'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Product Groups

  • Form Builder
  • ProFields
  • ProCache
  • ProMailer
  • Login Register Pro
  • ProDrafts
  • ListerPro
  • ProDevTools
  • Likes
  • Custom Development

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

  1. Hi again fellow PWers, A while back I created a newUser module that added a new user when a page (student) was added. This all works great. Today I'm trying to add a delete function to this same module (as we were getting leftover users when students were deleted) but it's throwing NullPage errors. I tried changing the hookAfter to hook Before but am still getting errors. Also strangely it's causing an issue when trying to delete these pages from the trash. I'm getting a "this page cannot be deleted" error. Any pointers would be greatly appreciated ------------------------------------------------------------ <?php class Createnewuser extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Create a new user', 'version' => 101, 'summary' => 'Creates a new user and edits an existing member on saving a member page.', 'singular' => true, 'autoload' => true, ); } public function init() { $this->pages->addHookAfter('added', $this, 'createTheUser'); $this->pages->addHookAfter('save', $this, 'updateTheUser'); $this->pages->addHookBefore('delete', $this, 'deleteTheUser'); } public function createTheUser($event) { $page = $event->arguments[0]; if($page->template == 'student'){ $newuser = new User(); $newuser->of(false); $newuser->name = $page->name; $newuser->pass = $page->password; $newuser->save(); $this->message("New user also added $newuser->name."); } } public function updateTheUser($event) { $page = $event->arguments[0]; if($page->template == 'student'){ $the_user = $this->users->get("name=$page->name"); $the_user->of(false); if ($page->isChanged("password")) { $the_user->pass = $page->password; } if ($page->isChanged("email")) { $the_user->email = $page->email; } $the_user->save(); $this->message("User $the_user->name also updated."); } } public function deleteTheUser($event) { $page = $event->arguments[0]; if($page->template == 'student'){ $the_user = $this->users->get("name=$page->name"); $the_user->delete(); } } }
  2. I know it is standard for a PHP setup to have a working mail() function, but I'm doing some work on a server where the local SMTP server has been disabled. While it's fairly trivial to set the SMTP server global variable to a remote server, it's impossible to setup authentication into the remote SMTP server. Therefore it would be useful to be able to hook into any functions which send email (eg forgotten password for admin login) and override it with phpMailer (or similar).
  3. Hello, I'd like to log all the messages and errors my site throws. Is there a way to hook into these methods? Thanks, thomas
  4. I've had a little look at the page cloning module and am trying to figure out a way of doing something similar whereby when a page of type member gets added, a new "user" page is also added, with the same name. Would this be something that could be done using this tool or would I be able to do something with a page save hook? If so, any tips on where to get started? I've already achieved this through front end forms and the API but as the rest of the administration in this case runs through the backend I thought it may be more logical to use the admin. Thank you.
  5. Hello, maybe it's too late or I had too little coffee or something else is sitting on my brain but I can't figure this out. I want to build a hook that determines if the User Agent is a phone and set a session variable accordingly: $this->addHookBefore('Page::render', $this, 'checkMobile'); function checkMobile(HookEvent $event) { $page = $event->object; $session = wire('session'); $domain = preg_replace("/^(m\.)/",'',$_SERVER['HTTP_HOST']); # this is to force one version or the other: if(wire('input')->get->v == 'desktop') { $session->isMobile = 'no'; } if(wire('input')->get->v == 'mobile') { $session->isMobile = 'yes'; } # /force # here comes mobile detection via Mobile_Detect if(!$session->isMobile) { require(wire('config')->paths->root.'/Mobile_Detect.php'); $detect = new Mobile_Detect(); $session->isMobile = $detect->isMobile()?'yes':'no'; } # /mobile detection # now for the redirects. This is cosmetics but I would like it to work: if ($session->isMobile == "yes" && !preg_match("/\bm./", wire('config')->httpHost)) { wire("session")->redirect("//m.".$domain.$page->url); } if ($session->isMobile == "no" && preg_match("/\bm./", wire('config')->httpHost)) { $session->redirect("//".$domain.$page->url); } } The idea is, that if someone visits bmxrider.de on a mobile, he gets redirected to m.bmxrider.de and $session->isMobile is set to yes so I can change the templates later on. I also like to be able to force each version by setting $input->get->v Whenever I use the query string to "force" a state, my site ends up in endless redirects. I checked the logs and it looks like $session->isMobile toggles between yes and no and I have no idea, why this happens. Can someone help me out? Thanks, thomas Update: The eternal redirect happens, when the domain doesn't match the query string. Like m.bmxrider/?v=desktop or bmxrider/?v=mobile
  6. Little bit of background: I'm trying to use (and hack) Multisite-module by @apeisa for a client project, but got stuck on one somewhat annoying problem: it doesn't do anything to $page->rootParent(), thus that still returns site root or first page after that, which isn't very useful here. Most straightforward way to override this would seem to be hooking into rootParent and altering it's return value or completely replacing it with my own method. I've tested this with local installation and this method seems to work. So, my question is: would it be possible to make $page->rootParent() hookable or do I have to hack my way around this problem? Not really sure if altering rootParent is a common need, but it sounds justified in cases where you're overwriting PW URL scheme somehow (like Antti's Multisite module does.) Of course if there's a better way, I'm open for ideas too
  7. Is there any way to manipulate the form created by ProcessField's not hookable method buildEditForm? It's used by the hookable executeEdit method. But by adding a hook after executeEdit, I just can access the rendered HTML code executeEdit returns. Changing the markup is definitely not the way to go here. Adding a hook before is also useless, as the buildEditForm is called after the hook would have been executed. The only idea I got is to set the form property through a hook before, as it would be used by executeEdit if it already is set. public function ___executeEdit() { if(is_null($this->form)) $this->buildEditForm(); ... But as I can't access the protected buildEditForm method from outside the class, it seems there is just the way to copy buildEditForm completely, change it and use it to set ProcessField's form property before executeEdit instead of just accessing the form to perform minor changes or additions. Anyone a better idea? Or would it make sense to make the form generation more accessible for hooks?
  8. Hi, Like the title says, is there a way to check what the values were before saving, to check for fields that have changed etc. Both the before and after event now seems to get the Page object after it has been updated.
  9. I am trying to extend InputfieldImage & FieldtypeImage. I want something like this: $page->image->action('param'); When I call method action() i want read settings saved with my ExtendedInputImageField field. Then i want perform action based on that settings. I have first part. I can save EntendedInputImageField settings when I configure new field. In this way I save the settings: public function ___getConfigInputfields() { $inputfields = parent::___getConfigInputfields(); //[...] $field = $this->modules->get("InputfieldTextarea"); $field->attr('name', 'advSetting'); $field->attr('value', $this->advSetting? (string) $this->advSetting : ''); $field->label = $this->_("Advenced Settings"); $field->description =''; $fieldset->add($field); //[...] $inputfields->add($fieldset); return $inputfields; } <?php Pageimage::action Hook class FieldtypeExtendedImage extends FieldtypeImage { // [...] public function init() { $this->addHook('Pageimage::action', $this, 'action'); } public function action(HookEvent $event) { // How can I read 'advSetting' settings here? } //[...] }
×
×
  • Create New...