Jump to content

Recommended Posts

Posted

My page has a repeater field with several fields as well as an image.

In my module I tried to output all page fields.

        $page->of(false);
        foreach($page->fields as $field) {
             if ($field->type instanceof FieldtypeRepeater) {
                foreach($page->{$field->name} as $repeater) {
                    foreach($repeater->fields as $rf) {
                        print $rf->name . ': ';
                        var_dump($repeater->{$rf->name});
                    }
                }
            }
         }

I got the following output:

title: string(0) ""
colors: object(ProcessWire\SelectableOptionArray)#497 (2) {
  ["count"]=>
  int(1)
  ["items"]=>
  array(1) {
    [1]=>
    int(1)
  }
}
content: string(0) ""
component_position: object(ProcessWire\SelectableOptionArray)#501 (2) {
  ["count"]=>
  int(1)
  ["items"]=>
  array(1) {
    [1]=>
    int(1)
  }
}
image: NULL
link_title: string(0) ""
link_url: bool(false)

However, shouldn't empty image field return

object(ProcessWire\Pageimages)#501 (1) { ["count"]=> int(0) } 

???

For example, when I use Custom Upload Names module it has these lines

elseif($field->type instanceof FieldtypeRepeater) {
                    foreach($editedPage->{$field->name} as $repeater) {

                        //make sure repeater item actually exists already, which is important when you have added items beyond those initially rendered.
                        //fixes this issue: https://github.com/ryancramerdesign/ProcessWire/issues/1541
                        if(!$repeater->id) continue;

                        foreach($repeater->fields as $rf) {
                            if($rf->type instanceof FieldtypeFile) {
                                if(count($repeater->{$rf->name})) {
                                    foreach($repeater->{$rf->name} as $file) {
                                        if(!$file) continue;
                                        $files[$file->name] = $repeater->id.'|'.$rf->id; // add filename with respective repeater pageid and fieldid to array
                                    }
                                }
                            }
                        }
                    }
                }
            }

and they output Pageimages (tried debugging by moving pages in admin), even if there is no image.

My Processwire version is 3.0.97.

Posted

Yes, when you try to output a image field from a module, hook or bootstrap script it is an array, even if you set it to single in the back-end. ?

  • Like 1
Posted
22 hours ago, AndZyk said:

Yes, when you try to output a image field from a module, hook or bootstrap script it is an array, even if you set it to single in the back-end. ?

Yes, the output format was the problem, but I still run it inside a module, but had to explicitly loop through Repeater fields and set output formatting to false.

Curious why it does not do by default, when I set the page formatting to false.

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.
×
×
  • Create New...