Jump to content

PWaddict

Members
  • Posts

    908
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by PWaddict

  1. If I use the following hook, with 2 languages works fine but with 1 language I have to press the Save button twice for the title field to get updated:

    $wire->addHookBefore('ProcessPageEdit::processInput', function(HookEvent $event) {
    
      $page = $event->object->getPage();
    
      if($page->template == "mytemplate") {
        $page->title = $page->venue . ", " . $page->city . ", " . $page->country->title . ", " . $page->getFormatted("date");
      }
    });

    ?

  2. 5 minutes ago, clsource said:

    https://processwire.com/api/ref/languages/get-default/

    
    $wire->addHookBefore("Pages::saveReady", function(HookEvent $event) {
    
      $page = $event->arguments(0);
      if($page->template->name != 'mytemplate') return;
    
      if(count(wire("languages")) > 1) {
      	$defaultLang = wire("languages")->getDefault();
      	$page->title->setLanguageValue($defaultLang, "New Value");
      } else {
        $page->title = "New value";
      }
    
      $event->arguments(0, $page);
    });

     

    That was I'm trying and it works but it doesn't work with only just 1 language when using fields to get the title value.

    $wire->addHookBefore("Pages::saveReady", function(HookEvent $event) {
    
      $page = $event->arguments(0);
      if($page->template->name != 'mytemplate') return;
    
      if(count(wire("languages")) > 1) {
      	$defaultLang = wire("languages")->getDefault();
      	$page->title->setLanguageValue($defaultLang, $page->venue . ", " . $page->city . ", " . $page->country->title . ", " . $page->getFormatted("date"));
      } else {
        $page->title = $page->venue . ", " . $page->city . ", " . $page->country->title . ", " . $page->getFormatted("date");
      }
    
      $event->arguments(0, $page);
    });

     

  3. 7 minutes ago, clsource said:

    May be this can work?

    https://processwire.com/api/ref/pages-type/save-ready/

    
    $wire->addHookBefore("Pages::saveReady", function(HookEvent $event) {
    
      $page = $event->arguments(0);
      if($page->template->name != 'mytemplate') return;
    
      $defaultLang = wire("languages")->get("default");
      $page->title->setLanguageValue($defaultLang, "New Value");
      $event->arguments(0, $page);
    });

     

    Thanks, this seems to work if I have 2 languages but it doesn't work if I have only 1 and I don't understand why cause it's the default language for both cases. I need it to work with 1 or additional languages.

  4. I'm using the following hook in site/ready.php to manipulate page title in admin section and it work fine in localhost but I just noticed that it doesn't work on live server. I'm always getting "Untitled" even though all 4 fields have values.

    $wire->addHookAfter("Pages::saveReady", function(HookEvent $event) {
    
      $page = $event->arguments[0];
      if($page->template->name != 'mytemplate') return;
    
      if($page->myfield_text_a && $page->myfield_text_b && $page->myfield_options && $page->myfield_date) {
        $page->title = $page->myfield_text_a . ", " . $page->myfield_text_b . ", " . $page->myfield_options->title . ", " . $page->getFormatted("myfield_date");
      } else {
        $page->title = "Untitled";
      }
    
    });

    How is this possible???

  5. I'm getting hundreds of PHP notices and 1 warning when visiting sitemap.xml url with debug enabled. With debug disabled everything seems ok. 

    Using PW 3.0.165 and PHP 7.4.9.

    Notice: Trying to access array offset on value of type null in C:\laragon\www\mysite\site\assets\cache\FileCompiler\site\modules\MarkupSitemap\MarkupSitemap.module.php on line 413
    
    Notice: Trying to access array offset on value of type null in C:\laragon\www\mysite\site\assets\cache\FileCompiler\site\modules\MarkupSitemap\MarkupSitemap.module.php on line 417
    
    Notice: Trying to access array offset on value of type null in C:\laragon\www\mysite\site\assets\cache\FileCompiler\site\modules\MarkupSitemap\MarkupSitemap.module.php on line 427
    
    Notice: Trying to access array offset on value of type null in C:\laragon\www\mysite\site\assets\cache\FileCompiler\site\modules\MarkupSitemap\MarkupSitemap.module.php on line 353
    
    Warning: Cannot modify header information - headers already sent by (output started at C:\laragon\www\mysite\site\assets\cache\FileCompiler\site\modules\MarkupSitemap\MarkupSitemap.module.php:427) in C:\laragon\www\mysite\site\assets\cache\FileCompiler\site\modules\MarkupSitemap\MarkupSitemap.module.php on line 192

     

  6. 3 minutes ago, adrian said:

    Maybe I could programmatically replace mtime with modified. Can you think of any reason why mtime would actually be needed vs modified?

    modified: Unix timestamp of when Pagefile (file, description or tags) was last modified.
    mtime: Unix timestamp of when file (only) was last modified.

    Taken from Pagefile API Reference.

  7. 9 hours ago, adrian said:

    I noticed though that it all works fine if you use $file->modified instead. Would that work ok for your needs instead of mtime?

    Thanks a lot. I switched from mtime to modified and the problem is gone :) Maybe you should add a note on the Rename rules to avoid using mtime.

  8. 3 minutes ago, adrian said:

    Ok, I think I have narrowed it down - if you don't have "overwrite" checked and you use $file->mtime it doesn't know how to name the file at the correct point it needs to. Let me see if I can fix.

    Yep, I'm getting the same results with you.

    • Like 1
  9. The structure on my template is in this order:

    various fields
    Image field
    Repeater field
    Repeater field
    various fields

    The image doesn't display on frontend because it seems that it doesn't get saved in database??? I'm checking if the image exists like this: if($page->image) etc. There is nothing wrong in the code on template cause if I save the page AGAIN then this time the image is properly getting saved and displayed on frontend.

    Image Maximum files allowed: 1
    Formatted value: Automatic

    EDIT: It's a multi-language site.

  10. Hello @adrian

    Today I noticed a very strange behaviour with the module. If I upload an image on the Image or CroppableImage3 field and then add a new repeater item on a repeater field and publish / save the page, the image doesn't display on front-end. The image and its variations are visible on back-end and on the related folder in assets.

    If I first add a new repeater item on a repeater field and then upload an image on the Image or CroppableImage3 field then there is NO problem. WTF?

    I verified that this is caused by the module cause when I temporarily disable the rule there was NO problem. My rule is: {$page->title}_{$file->mtime} with Rename on Save checked.

    I'm using PW 3.0.135.

  11. Hello. Today I noticed a very strange behaviour. If I upload an image on the Image or CroppableImage3 field and then add a new repeater item on a repeater field and publish / save the page, the image doesn't display on front-end. The image and its variations are visible on back-end and on the related folder in assets.

    If I first add a new repeater item on a repeater field and then upload an image on the Image or CroppableImage3 field then there is NO problem. WTF?

    I'm using PW 3.0.135.

    Can PLEASE someone help me?

    EDIT: It seems the issue is caused by Custom Upload Names module. I will post on the related topic.

×
×
  • Create New...