Jump to content

Search the Community

Showing results for tags 'adminactions'.

  • 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

Found 2 results

  1. I have a multilingual PW installation with default (Deutsch) english (English) I have imported a lot of pages and I created a Admin Action that lets me upload a CSV file and set the fields on the page which worked fine. I'm now trying to set the names of the german and the english page according to the page's title. so I here's my code: protected function executeAction($options) { $url = config()->paths->assets.'cache/AdminActions/'; if (count($options['csv_upload'])) { $n = 0; $file = $options['csv_upload']->first(); $fp = fopen($file->filename, 'r'); $count = 0; while (($row = fgetcsv($fp, 0, ',', '"')) !== false) { $count++; if (++$n === 1) { // Store the field names based on the first row of the CSV $fieldNames = $row; continue; } // Get the page_id from the first column of the current row $page_id = $row[0]; $target_page = pages()->get("id=$page_id"); if ($target_page->id) { $target_page->of(false); // Set the field values dynamically based on the field names and row values foreach ($fieldNames as $index => $fieldName) { if ($fieldName !== 'page_id') { $fieldValue = $row[$index]; $target_page->set($fieldName, $fieldValue); if ($fieldName == 'title_de') { $name = wire('sanitizer')->name($fieldValue, true, 128, '-'); $target_page->setName($name, 'default'); } if ($fieldName == 'title_en') { $name = wire('sanitizer')->name($fieldValue, true, 128, '-'); $target_page->setName($name, 'english'); } } } $target_page->save(); $target_page->of(true); } else { $this->error("$target_page is not a project"); continue; } $target_page->of(true); } $this->successMessage = "$count CSV rows were processed."; fclose($fp); $this->wire('files')->unlink($file->filename); return true; } else { $this->failureMessage = 'Please upload a CSV file'; return false; } I managed to set all other multilingual fields of the pages just fine when having the right language active for my user. It seems to be different for the name though, I think I need to use $target_page->setName($name, 'english'); for it to work. However, the results are inconsistent, especially when I have multiple pages with the same title. (German page gets the English name, English name doesn't get a -1 (or -2, or -3) added to the end). I cannot quite put my finger on how that works exactly, but it seems to depend on whichever language is active for my user. First I thought the language status of the page (status1021 for english in my case) cause the problem, it was set to 0, so I changed that to 1 but that didn't help either. So now I ended up with inconsistencies, e.g. the same name and url for pages with the same title which results in a 404 for all of them. And now even changing it manually doesn't fix it. Thanks for help!
  2. a checkbox field cannot be checked by default? also: Admin Action "Field Set or Search and Replace" cannot batch set a checkbox field's value? 😑
×
×
  • Create New...