Jump to content

easynowbaby

Members
  • Posts

    15
  • Joined

  • Last visited

Profile Information

  • Gender
    Female

Recent Profile Visitors

1,028 profile views

easynowbaby's Achievements

Jr. Member

Jr. Member (3/6)

0

Reputation

  1. Thank you for your reply, but my problem lies elsewhere. The page is not created via admin, I use PW as a backend for a SPA, so it is being created via api and I'm trying to access fields that are not empty. Basically I'm trying to do something like this: $p->order_status->first->title->getLanguageValue(1027) This works in a different hook (ProcessPageEdit::processInput) but not in published or added. Any ideas appreciated...
  2. Hello everyone, I have a hook in my module that's hooking after a page was created. Inside of it I need to access the data of the newly created page and send the data in an email. My problem is that whenever I try to access a page reference type of field, it seems that it's empty. Here's the hook: public function ready() { $this->pages->addHookAfter('added', function ($event) { $p = $event->arguments[0]; if ($p->template == "order") { // accessing page reference fields here doesn't work } }); } Any help would be greatly appreciated!
  3. I decided to delegate this problem to gulp. If anyone is interested, I used this package https://github.com/sindresorhus/gulp-rev I used this modified function for implementation: function asset_path($filename) { $manifest_path = wire('config')->paths->templates . 'versioned/rev-manifest.json'; if (file_exists($manifest_path)) { $manifest = json_decode(file_get_contents($manifest_path), TRUE); } else { $manifest = []; } if (array_key_exists($filename, $manifest)) { return $manifest[$filename]; } return $filename; } and then in my templates <?php if ($config->debug): ?> <link rel="stylesheet" href="<?php echo $config->urls->templates . 'build/main.css'; ?>"> <?php else: ?> <link rel="stylesheet" href="<?php echo $config->urls->templates . 'versioned/' . asset_path('main.css'); ?>"> <?php endif; ?>
  4. Hello, what would be the recommended way of versioning your asset files (css and js)? I know it can be done with AIOM module but it seems it's not longer maintained, since it doesn't work on PHP 7.1. Can anyone recommend any best practices for this? Thanks!
  5. After further investigation it seems that both answers are correct, the problem was something else. For some reason my hook is being fired every time any page is loaded, not just after saveOrder function is being run, as I intended to. For the time being, my workaround is to wrap everything in my registerUser function in an if statement: public function registerUser($event) { if ($event) { $order = $event->arguments('order'); if ($order->pad_register) { .... } } } I would love an explanation why is this happening if anyone has one
  6. Thank you for your reply but I keep getting the same error
  7. Hi, I'm trying to create a simple module, that is hooking into a certain function in Padloper that returns a filled form. I want to use these data to create a new user. But when I try to create a page I'm getting this error: Call to a member function get() on null (line 30) Here is my module: <?php class RegisterUser extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Registration during checkout', 'version' => 1, 'summary' => 'Register user during checkout', 'singular' => true, 'autoload' => true, 'icon' => 'user', ); } public function init() { /* */ $this->addHookBefore('PadOrderProcess::saveOrder', $this, 'registerUser'); } /** * This is the method that hook run. Since in Padloper we can have any field as pricefield, * we need to find out which is the pricefield. */ public function registerUser($event) { // This way we can access the arguments that are send to hooked method $hp = wire('pages')->get(1); $p = new Page(); $p->of(false); // sets output formatting to false in order to change field values. $p->parent = $hp; $p->template = "basic-page"; $p->title = 'test2'; // sanitized your value from form and sets to title $p->save(); // save the new page } } This is my first time working with hooks, so maybe I'm missing something. Maybe hooks are strictly for modifying arguments sent to hooked methods? Thank you for any help!
  8. Looks like I found a solution after all, so excuse me for spamming. It seems that pageTable picks up on pages not created directly through it (i.e. if you create a page directly under a specified parent), but it cannot detect pages that already exist. This post seems to help though:
  9. Hi all! I would like to use pageTable with existing pages. The page I wanna use the pageTable on is not the parent of pageTable items. But when I add the pageTable field to the page ti shows no data. I used it like this in the past and I was able to add orphans using checboxes. Am I doing something wrong or was maybe pageTable updated in some way that it´s not supported now? Thank you!
  10. Thanks Pierre-Luc, wire('users') worked like a charm!
  11. Hello all, for the first time I need help from the great people of this great forum! I am trying to add new functionality to admin, namely sending emails from the edit page. I want to add an extra "Send email" button, which I did using this snippet. Here is my modified code: <?php class HookPageEdit extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Hook PageEdit', 'version' => 1, 'summary' => '', 'singular' => true, 'autoload' => true, ); } public function init() { $this->addHookAfter('ProcessPageEdit::buildForm', $this, 'addInputs'); $this->addHookBefore('ProcessPageEdit::processInput', $this, 'sendMail'); } public function addInputs($event) { $page = $event->object->getPage(); if($page->template == "email"){ $form = $event->return; $accept = $this->modules->get('InputfieldSubmit'); $accept->attr('id+name', 'hook_accept_application'); $accept->class .= ' ui-priority-secondary head_button_clone'; $accept->attr('value', $this->_('Send email')); $f = $this->modules->get('InputfieldCheckbox'); $f->attr('name', 'checkbox_all_users'); $f->label = 'Send to all'; $f->attr('value', $this->checkbox_all_users ? $this->checkbox_all_users : 0 ); $f->attr('checked', $this->checkbox_all_users === 1 ? 'checked' : '' ); $form->insertBefore($accept, $form->get("id")); $form->insertBefore($f, $form->get("id")); } } public function sendMail($event) { if($this->input->post->hook_accept_application){ $page = $event->object->getPage(); $event->replace = true; if(!$page->id){ $this->error("Invalid application to be accepted."); return; } $toAll = $this->input->post->checkbox_all_users; if ($toAll) { $users = $users->find("roles=member,guest"); } } } } But I get an error saying that $users is null. Anyone knows how to access users in my module? Also, is this a good way of doing what I need? Thanks a lot!
×
×
  • Create New...