adrian

Batch Child Editor

Recommended Posts

Thanks @sodesign - looks like you are using a Page Reference field that only accepts a single value, under Details >  Page field value type - is that correct?

I think I must not have properly tested with Single. Can you please try replacing:

            if(!$pageMatch->id && $title!='') {

with:

            if(!$pageMatch->id && $childFieldValue!='') {

here:

https://github.com/adrianbj/BatchChildEditor/blob/f3a77b5338fd69b14b939edbae9948f42af2fc14/BatchChildEditor.module#L1675

Please let me know if that works.

Share this post


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

Perfect, that's now working without error.

Thank you for resolving this!

No worries - thanks for reporting and helping to debug.

I have committed a new version with this fix.

  • Like 1

Share this post


Link to post
Share on other sites

Just a quick follow-up to this - I have been importing more content in a tsv and ran across another issue.

When the title of the page being matched contains a comma, the selector in the line above throws an error.

$pageMatch = $this->wire('pages')->get("id=$options, title={$childFieldValue}");

An example page title is "Fixed Height, Loop Leg" - The error was from the Selector class, and the snippet included something to the effect of: "field: Fixed, value: Height "

I think this was why I had used the selector value sanitizer method previously.

I tried this:

$pageMatch = $this->wire('pages')->get("id=$options, title={$this('sanitizer')->selectorValue($childFieldValue)}");

The import runs successfully, though I'm unsure if this might have knock-on effects elsewhere.

 

  • Like 1

Share this post


Link to post
Share on other sites

Thanks again @sodesign - I have added that on that line, and also a few others.

Please test the latest version.

Share this post


Link to post
Share on other sites

@adrian

Got this error after install and trying to edit a page.

Error: Uncaught Error: Call to a member function getLanguageValue() on null in .../site/modules/BatchChildEditor/BatchChildEditor.module:860

The error occurs due to the fact there is no title field assigned to the page template. I think your module should handle this since its easy to remove title now with the $template->noGlobal option.


.. and this one in the exported csv file after using the template you provided in the README.md

<br />
<b>Notice</b>:  Undefined index: configurablePages in <b>.../site/assets/cache/FileCompiler/site/modules/BatchChildEditor/ProcessChildrenCsvExport.module</b> on line <b>94</b><br />
<br />
<b>Warning</b>:  in_array() expects parameter 2 to be array, null given in <b>.../site/assets/cache/FileCompiler/site/modules/BatchChildEditor/ProcessChildrenCsvExport.module</b> on line <b>94</b><br />
<br />

 

Edited by kixe
2nd error

Share this post


Link to post
Share on other sites

First is fixed. Thanks. :rolleyes:
While playing around getting still some notices:

Notice:  Trying to get property of non-object in .../site/assets/cache/FileCompiler/site/modules/BatchChildEditor/ProcessChildrenCsvExport.module on line 230

https://github.com/adrianbj/BatchChildEditor/blob/2e079d342ea56ac7be58ae2de4d6cdc1317eec0e/ProcessChildrenCsvExport.module#L230

check wire('fields')->$fieldName first

Notice:  Trying to get property of non-object in .../site/assets/cache/FileCompiler/site/modules/BatchChildEditor/ProcessChildrenCsvExport.module on line 161

https://github.com/adrianbj/BatchChildEditor/blob/master/ProcessChildrenCsvExport.module#L161

field label expected but field label is not required. Needs fallback to name.

 

Share this post


Link to post
Share on other sites

Sorry about the other notices - I have never dealt with templates without a title field before.

Any chance you feel like putting together a PR for these as you find them? Sorry, I am not going to have much time for my PW modules for a while.

Thanks!

Share this post


Link to post
Share on other sites

I ended up with the following simple template since I was just looking for a csv export/ download option. It works without any errors for any kind of field (repeaters included)

<?php
// template provides file download of some children data in csv format
// export as CSV if $_GET['csv_export‘] == 1 is in url
if(isset($input->get->csv_export) && $input->get->csv_export == 1) {
    // create data array
    $data = $page->children->explode(function($item){
        return array(
            'ID'=> $item->id, // page property
            'Author' => $item->author->first()->name, // page field
            'Length' => $item->timeslots? $item->timeslots * 30 : 0, // integer field
            'Info' => $item->info // runtime markup field
        );
    });
    // set header
    header("Content-type: text/csv");
    header("Content-Disposition: attachment; filename=file.csv");
    header("Pragma: no-cache");
    header("Expires: 0");
    $output = fopen("php://output", "wb");
    foreach ($data as $fields) fputcsv($output, $fields);
    fclose($output);
    exit;
}
// display content of template with link to same page with appended csv_export=1
else {
   $page->_content = "<a href='./?csv_export=1'>Export Child Pages as CSV</a>"; //link to initiate export
}

 

  • Like 1

Share this post


Link to post
Share on other sites
19 hours ago, kixe said:

I ended up with the following simple template since I was just looking for a csv export/ download option. It works without any errors for any kind of field (repeaters included)


<?php
// template provides file download of some children data in csv format
// export as CSV if $_GET['csv_export‘] == 1 is in url
if(isset($input->get->csv_export) && $input->get->csv_export == 1) {
    // create data array
    $data = $page->children->explode(function($item){
        return array(
            'ID'=> $item->id, // page property
            'Author' => $item->author->first()->name, // page field
            'Length' => $item->timeslots? $item->timeslots * 30 : 0, // integer field
            'Info' => $item->info // runtime markup field
        );
    });
    // set header
    header("Content-type: text/csv");
    header("Content-Disposition: attachment; filename=file.csv");
    header("Pragma: no-cache");
    header("Expires: 0");
    $output = fopen("php://output", "wb");
    foreach ($data as $fields) fputcsv($output, $fields);
    fclose($output);
    exit;
}
// display content of template with link to same page with appended csv_export=1
else {
   $page->_content = "<a href='./?csv_export=1'>Export Child Pages as CSV</a>"; //link to initiate export
}

 

Will be willing to test anytime!! I have tons of pages with repeaters to export in CSV... :-)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Lex Sanchez
      Video or Social Post Embed
      Based on the TextformatterVideoEmbed module developed by Ryan Cramer, we have added the possibility to embed publications of the main social networks Facebook, Twitter and Instagram.
      ProcessWire Textformatter module that enables translation of YouTube, Vimeo, Instagram, Facebook, Twitter or Issuu URLs to full embed codes, resulting in a viewable video or social post in textarea fields you apply it to.
      How to install
      Download or Clone from Github: https://github.com/lexsanchez/VideoOrSocialPostEmbed
      Copy the VideoOrSocialPostEmbed.module file to your /site/modules/ directory (or place it in /site/modules/VideoOrSocialPostEmbed/).
      Click check for new modules in ProcessWire Admin Modules screen. Click install for the module labeled: "Video or Social Post Embed".
      Now you will be on the module config screen. Please make note of the config options and set as you see fit.
      How to use
      Edit your body field in Setup > Fields (or whatever field(s) you will be placing videos in). On the details tab, find the Text Formatters field and select "Video or Social Post Embed". Save.
      Edit a page using the field you edited and paste in YouTube, Vimeo, Facebook, Twitter, Instagram and/or Issuu URLs each on their own paragraph.
      Example
      How it might look in your editor (like TinyMCE):
      How it works
      This module uses YouTube, Vimeo, Instagram, Facebook, Twitter and Issuu oEmbed services to generate the embed codes populated in your content. After these services are queried the first time, the embed code is cached so that it doesn't need to be pulled again.
      Configuration
      You may want to update the max width and max height settings on the module's configuration screen. You should make these consistent with what is supported by your site design.
      If you change these max width / max height settings you may also want to check the box to clear cache, so that YouTube/Vimeo/Facebook/Twitter/Instagram/Issuu oembed services will generate new embed codes for you.
      Using with Markdown, Textile or other LML
      This text formatter is looking for a YouTube, Vimeo, Instagram, Facebook, Twitter or Issuu video URL surrounded by paragraph tags. As a result, if you are using Markdown or Textile (or something else like it) you want that text formatter to run before this one. That ensures that the expected paragraph tags will be present when VideoOrSocialPostEmbed runs. You can control the order that text formatters are run in by drag/drop sorting in the field editor.
      Copyright 2018 by Ryan Cramer / Updated by Lex Sanchez
    • By kixe
      Email Verification
      This module provides functions to validate email adresses and hosts. The module generates a textfile for blacklisted mailhosts (trashmail), which will be always up to date.
      Download
      https://modules.processwire.com/modules/email-verification/
      API
      // get module $mailcheck = $modules->get('EmailVerification'); // return bool/ string - automatted update of blacklist file $mailcheck->blacklisted(email|domain) // return bool - validate a top level domain, checks against IANA list $mailcheck->validTLD(tld) // return array of punycoded TLDs - cyclic updated, data pulled from IANA $mailcheck->getTLDs(cycle=2592000) // return bool - checks syntax converts to punycode $mailcheck->validDomainName(domain); // return bool - checks punycode encoded syntax $mailcheck->validHostName(host); // return bool - checks syntax and accessibility $mailcheck->validHost(email|domain) // add a single value to blacklist $mailcheck->addToBlacklist(email|domain) USAGE
      $mailcheck = $modules->get('EmailCheck'); $email = 'susi@trashmail.com'; if($mailcheck->blacklisted($email)) echo 'Email Provider not allowed'; if(!$mailcheck->validHost($email)) echo 'Mailhost not available'; Example blacklist file:  blacklist.txt
       
    • By teppo
      Code Blocks Textformatter is a tiny Textformatter module I cooked up to add support for code blocks to text/textarea/RTE fields on some of the sites I work with. Unlike a full-blown Markdown Textformatter – which is something that we already have in the core – this module simply adds support for fenced and inline code blocks.
      The syntax is based on the GitHub code block documentation, so please refer to that for additional instructions. The README at GitHub also includes some basic examples. As with any Textformatter, in order to enable this one, install it and enable it via field settings. Note that there's no syntax highlighting built in (at least for the time being), so use a tool of your choice for that – personally I prefer Prism.js.
      Since this module doesn't use a Markdown tool behind the scenes, but rather some home baked regular expressions, there's always the possibility that I've missed something – but please let me know if you use this module and run into any issues. On the other hand this module should be relatively fast and unobtrusive, as there are no unnecessary bits of code to run 
      GitHub repository: https://github.com/teppokoivula/TextformatterCodeBlocks Modules directory: http://modules.processwire.com/modules/textformatter-code-blocks/
    • By theo
      Here is my first processwire module (beta).
      https://github.com/theo222/ImagePickerField
      A lot of "first times". First time Github, Markdown and of course PW Modules.
      So be gentle please.
      I hope it works.