Jump to content

Robin S

Members
  • Posts

    5,009
  • Joined

  • Days Won

    333

Everything posted by Robin S

  1. No solution currently (other than switch from Repeater to PageTable). But issues logged at GitHub: #1567, #1616
  2. Thanks, I've taken that advice and everything works great. Sanitizing to an image object means I avoid having to check for object vs. string in the sleepValue method. For novice developers like myself I think it's a bit hard to grasp the sanitizeValue method because it's not obvious where the method is called. With some debugging it looks to me like sanitizeValue is called twice, with the flow being: inputfield > sanitizeValue > sleepValue > database and database > wakeupValue > sanitizeValue > page Is that correct? It's the first call that puzzles me a bit because the comment in Fieldtype.php for sanitizeValue says: And I can't see where the "Page instance" comes into inputfield > sanitizeValue > sleepValue > database @kixe Thanks for directing me to your module - I haven't tried it before and it looks like it's very flexible. It's not quite suitable for my purposes for a few reasons: I want my select dropdown to include the images from all the image fields assigned to the template. Because each image field is a separate table in the database I don't think Fieldtype Select External Option will allow this. I want to customise the select inputfield so it shows a thumbnail of the selected image (so it's easier for the user to select the image they want). I'm doing this by setting a thumbnail data attribute for each option in the options array. So my module needs to be something specific to images rather than Fieldtype Select External Option which has a broader application. When used for image fields, it seems that the value saved by Fieldtype Select External Option is quite fragile. Because the option value has to be an integer you have to use the Sort column for the value. This means that if the images are reordered in the image field the image referenced by Fieldtype Select External Option is changed. For an image reference you really want the image name to be the value that is stored. Also, I got some errors when attempting to install Fieldtype Select External Option. They are caused by the strings that are marked as translatable. I think lines like... $f->label = _('Usage'); ...need to be... $f->label = $this->_('Usage');
  3. I'm working on a simple fieldtype module and trying to understand the wakeupValue, sleepValue and sanitizeValue methods a bit better. This and this have been helpful but I still have a few questions. My module is for storing a reference to an image that is contained in one of the image fields in a page. I'm using a customised select inputfield to choose from the available images, and the reference to the image is stored in the database as a string in the form: field_name|image_name In the wakeupValue method I convert the reference string to an image object. public function ___wakeupValue(Page $page, Field $field, $value) { list($field_name, $image_name) = explode("|", $value); $image = $page->$field_name->get("name=$image_name"); return $image; } This is working fine, but at the moment I'm not doing anything in the sanitizeValue method. To get an idea of when sanitizeValue is called I have this... public function sanitizeValue(Page $page, Field $field, $value) { $type = gettype($value); $log = wire("log"); $log->save("debug", "Sanitized: $value, Type: $type"); return $value; } ...and it shows that for every Edit Page save in admin the sanitizeValue method receives both the image reference string and the image object. Sanitized: photoxpress_8083749.jpg, Type: object Sanitized: images_two|photoxpress_8083749.jpg, Type: string Why does sanitizeValue get both these types? I can understand why the image object goes through sanitizeValue because I am setting that to the page, but why does the string go through sanitizeValue? I'm not setting the string to the page, just saving it to the database. For modules like this that store data in a different type than they send to the page, will the sanitizeValue method always need to account for both variable types? That is, the method can't expect $value to always be a string or always an object - it will need to test the type of $value and apply different sanitizing checks accordingly? And is this true for sleepValue also? Ryan said in another post: That makes sense if I was saving to my field via the API and set an image object to the field - sleepValue needs to convert the object to a reference string for storage in the database. But at the moment I'm only saving to the field via the admin, and so the $value received by sleepValue is a string coming from the inputfield, not an object. So to cover both bases I will need to test for the type of $value at the start of the sleepValue method? I guess I'm asking if this is the normal/right way for such a module to work or if there is some better way to set it up so that sanitizeValue and sleepValue only have to handle one variable type.
  4. Just to expand on this a bit: unlike the standard CKEditor image plugin, the PW image plugin does not provide a text field where you can type in a class for the image. So you would need to add "img-responsive" to a custom JS styles set and apply the class to the image using the styles dropdown. Info on how to load a custom style set is here. If you want the "img-responsive" class to be applied to every image in your CKEditor field (so you don't have to manually add it to every inserted image) there are a couple of options: 1. Add the class client-side with jQuery. This is a nice easy option. For example if your body text is inside a div with the class "body"... $(".body img").addClass("img-responsive"); 2. A little more challenging but no big deal if you're comfortable with PHP... create your own text formatter module that adds the class at runtime.
  5. +1 for this. As LostKobrakai pointed out, this wouldn't be an extension of FieldTypeImage. Maybe just an InputField like that used for Image, but storing a reference similar to a Page fieldtype. One case where this would be very useful is for selecting the image that will be used in the og:image meta tag. You want a single-image inputfield that selects from the images that have been already loaded to Image fields on the page. I'd love a field that has a setting for which page(s) images would be selectable from. So you could fix a page or pages (e.g. current page) in the settings, or allow the selection of a page from the inputfield (like what is possible in an RTE field). I think a field like this would be a great asset in PW - if there are use cases for selecting images from external Image fields within an RTE field then there are bound to be use cases for selecting them in a dedicated "image reference" field.
  6. +1 for a class/ID on the "maintenance mode" badge so it's position and appearance can be overridden. Would be cool if there were controls to set the text of the badge and the native PW message. Also, site editors who are not given permission to view the site in maintenance mode are put into an infinite redirect loop if they attempt to log in.
  7. Perfect, thanks!
  8. I have a page "go" using template "go" that I use for adding/updating pages via the API - I visit mysite.com/go and my code executes. It's convenient to keep this page in the tree so it's there when I need it but I worry about it being accidentally accessed (by me!), so I want a way to disable the page when I'm not using it. I thought unpublishing the page would do it, but it seems that the template code executes on visiting mysite.com/go even when the "go" page is unpublished. Is there a way to disable a page so it's template code does not execute? I'm also interested to learn other techniques that can be used to execute API code besides putting it in a template and accessing it from the frontend.
  9. I think it is in the systemIDs array: /processwire/ is the page titled "Admin", aka adminRootPageID Thanks for the link to the other thread - that answers the question of how the /processwire/ branch is hidden.
  10. Good solution, thanks! Just curious: what is it about the /processwire/ branch that makes it hidden to non-superusers? Is it possible to create new branches that are hidden like this?
  11. I'm using a PageTable field for the first time. I've set up the field so pages used in the PageTable field are stored under a separate "Tools" page. I want site editors to be able to view and edit PageTable pages via the PageTable field, but not see those pages in the page tree. Is that possible?
  12. I think your problem comes from this: $root = $page->parents->count == 1 ? $page : $page->parent; For the first two levels $root is "Products", but on the third level $root is "product 2" or whatever level 2 parent you are in. So you only see children of "product 2". I think this will do what you want: $root = $page->rootParent;
  13. I'm experiencing the same issue. If the repeater item is opened individually in Edit Page (via Find) then the image is editable but it is not editable in the context of the page containing the repeater field. Is this the expected behaviour for image fields in repeaters? Also, I notice that images in repeaters have a green header rather than the normal blue header. What is the significance of the green header?
  14. Update: I think the problem is more general. When using more than one text formatter (can be any text formatters) on a files or images field, only the first text formatter is applied. Can anyone confirm? Edit: filed issue at Github.
  15. I'm using the core "Markdown/Parsedown Extra" and "Paragraph Stripper" text formatters on the descriptions of an image field, via the field setup in admin. The paragraph stripper needs to come after the markdown formatter, but it seems the order the text formatters are applied is the opposite of what it should be. Edit: Sorry, my description of the problem was wrong there. But it seems there is some incompatibility with "Markdown/Parsedown Extra" and "Paragraph Stripper" when used together on image descriptions. If markdown is first and the paragraph stripper second then the paragraphs are not stripped. If paragraph stripper is first and markdown second (i.e. the wrong order) then the markdown formatter isn't applied at all. But the two text formatters seem to work correctly together for text fields. Please see update below
  16. Ryan, that selector would fail to match a page where text_field is "my cat and my dog" and page_field is "5555" (or empty). It's taken me a little while to get my head around the way OR-groups work, but my current understanding is that if you need an AND relationship between OR-groups (as I do in my example) then the OR-groups need to be named. Otherwise the effect is (or-group) OR (or-group) OR (or-group)...etc.
  17. That selector doesn't give quite the right results. There's no AND component to it, so it would match any page that has cat OR dog OR 1234 OR 4321. I think the selector in my third post... $pages->find("foo=(text_field*=cat), foo=(page_field=1234), bar=(text_field*=dog), bar=(page_field=4321)"); ...might be as succinct as it gets. And nothing wrong with it, I just thought there might be something simpler I was overlooking. It's also totally possible to use the $items->add approach you suggested initially, just a bit more involved to deal with the pagination. Found a great post from Soma that spells it out.
  18. Thanks. I considered the $items->add approach but it makes sorting and pagination more difficult than with a single find operation.
  19. $pages->find("foo=(text_field*=cat), foo=(page_field=1234), bar=(text_field*=dog), bar=(page_field=4321)"); Is that right? Anything more succinct that that possible?
  20. Problem solved - I just needed to give a name to the OR-group: $pages->find("foo=(text_field*=cat, page_field=1234), foo=(text_field*=dog, page_field=4321)"); Nope, that's not right. I'm going to kick myself when I get this...
  21. I'm sure there's a simple answer to this that's staring me in the face but I'm struggling to work out the right combination of pipe separators and OR-groups. How do I write a selector for the following: (text_field*=cat OR page_field=1234) AND (text_field*=dog OR page_field=4321)
  22. Thanks, that does the trick.
  23. I have several Page fields in my template, some are "multiple page" fields and some are "single page" fields. When looping through my template fields I need to also foreach the multiple page fields. What is a good way to test for multiple vs single page fields? Or if I know I want to loop through my Page fields is it better to set them all to dereference as PageArrays?
  24. Another option to consider is ProFields Table. For many things it's a good alternative to repeaters and the UI is a lot more compact.
  25. Form Builder has this functionality. Form submissions can be displayed in a table in the PW admin or saved as pages.
×
×
  • Create New...