Jump to content

fieldtype for storing image reference


Mikel
 Share

Recommended Posts

HI guys,

I am wondering if I am to focused on the problem, so that I don´t see an obvious solution, or that there is no elegant solution... ;-)

Ok, here is the usecase:

I am building a template with only one image-field that collects all needed images for that page. Also there are several repeater matrix fields: One for each section of the page. In each repeater matrix there is the possibility to choose one of the pages images for displaying it as "fullwidth section image" on frontend. At the moment I am doing this with a textarea, which is prone to errors, due to wrong user input.

Is there another possibility to store an image reference as a textarea?

Link to comment
Share on other sites

Hi, Zeka, thanks for the reply.

The goal is to upload about 30 to 50 images at once and then use them in individual sections of the page (template):
In "normal" textareas and in "special purpose" fields which actually just would need to store the image reference. With image fields you can only upload images, not choose already uploaded ones. (Or can you?)

Link to comment
Share on other sites

You maybe could use my module FieldtypeSelectExtOption in this case.

  1. install module
  2. create a field with this Fieldtype
  3. go to details tab of the new created field
  4. choose your preferred Inputfieldtype
  5. select the field holding your images as 'Source Table'
  6. save field
  7. select 'sort' for option value and whatever you want as 'label'
  8. set ther filter to 'pages_id = 1234' (1234 is a placeholder for the pages-id holding your image field and repeaters)
  9. save again
  10. add the field to your repeater matrix template
  11. done

Tell me if it works or if any problem occurs.

 

  • Like 4
Link to comment
Share on other sites

Hi, kixe, thanks for reminding me of your module!

It works the way you wrote, but I have one problem: The site we are working on is for a real estate company. The template in question must be reused for a lot of different projects. (=pages) 

So it does not work specifying the image field of only one page (filtering per id). The field created with your module should instead fetch all images of the page being edited. 

Link to comment
Share on other sites

// tested only backend part
$this->addHookAfter('FieldtypeSelectExtOption::filter', function($e) {
    if ($this->wire('page')->template == 'admin') {
        if ($this->wire('page')->process == 'ProcessPageEdit') $id = $this->wire('input')->get->id;
        else return;
    }
    else if ($this->wire('page') instanceof RepeaterPage) $id = $this->wire('page')->getForPage()->id;
    else $id = $this->wire('page')->id;
    $e->return = "pages_id='$id'";
});

 

Edited by kixe
modified code: hook admin only if ProcessPageEdit
  • Like 4
Link to comment
Share on other sites

Hi, kixe,

the backend is the only place where this is needed! But as I am actually a designer/part-time developer( with more or less growing knowledge of programming), could you please tell me where you placed the hook above? In a seperate module? Thanks!

Link to comment
Share on other sites

18 hours ago, kixe said:

You maybe could use my module FieldtypeSelectExtOption in this case.

  1. install module
  2. create a field with this Fieldtype
  3. go to details tab of the new created field
  4. choose your preferred Inputfieldtype
  5. select the field holding your images as 'Source Table'
  6. save field
  7. select 'sort' for option value and whatever you want as 'label'
  8. set ther filter to 'pages_id = 1234' (1234 is a placeholder for the pages-id holding your image field and repeaters)
  9. save again
  10. add the field to your repeater matrix template
  11. done

@kixe, when I try this (or use a hook to dynamically select a pages_id) there is always an option preselected in the inputfield. My SelectExternalOption field is not set to 'required'. Is it possible to have the first option in the inputfield blank (no selection)?

Link to comment
Share on other sites

  • 2 years later...

Hey @kixe, one question before trying this out: Is it possible to see image thumbnails to select from?

I have a use case where I need centralized stored icons and a select field for reference, that shows image thumbnails. Can I do that with your module?

 

Link to comment
Share on other sites

  • 1 month later...

@horst

Sorry for the very delayed answer. The module (FieldtypeSelectExtOption) is a fieldtype, not an inputfield. The fieldtype supports any Core Inputfieldtypes (Select, Radios, Checkboxes, SelectMultiple or ASMSelect) furthermore some 3d Party Inputfields like InputfieldChosenSelect. Read more about this in the README.md.

I don't know if there exists an Inputfield module which extends InputfieldSelect or InputfieldSelectMultiple showing icons or thumbnails to select from. Let me know if you find a solution.

  • Like 1
Link to comment
Share on other sites

@gmclelland here are screenshots of my use case and solution with the medialibrary module and the imagepicker module:

screen__imagepicker__with__medialibrary__1v2.thumb.png.050636bcaad874fec3e088e990ddb47f.png  screen__imagepicker__with__medialibrary__2v2.thumb.png.9bd9fc9c8160475749fb9c5cd34236bd.png

This is very nice solution. The site owner likes it. She can select completly visual. No distracting informations around. Just the icons. :)

  • Like 2
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By MarkE
      I have a selector:
      $pageArray = $pages->find("template=basic-page, length.magnitude>0, include=all"); I would like an array of each of the 'length' fields. However, the field is an object and $pageArray->each('length') returns the formatted values; I want the unformatted objects.
      I thought perhaps I could use a callable like:
      $pageArray = $pages->find("template=basic-page, length.magnitude>0, include=all"); $lengths = $pageArray->each(function($p) { $length = $p->getUnformatted('length'); return $length; }); but it seems that only strings can be returned and those are concatenated.
      So it looks like I have to use a foreach() loop - which works, but I was expecting some neater shorthand. Any thoughts?
    • By Webrocker
      Hi,
      I updated to the currently latest master (3.0.184) and now a lister (listerPro 1.1.3) preset shows the info cited in the title.
      According to this closed issue this is supposed to work <del>in 3.0.184</del>
      https://github.com/processwire/processwire-issues/issues/1428

      or is this a lister(pro) issue?

    • By sebr
      Hi
      I'm using Processwire 3.0.180.
      When I edit a page in admin, Tracy Debugger count between 50 and 100 pages loaded, depending on the templates. All pages open in less than a second.
      But when I edited pages from a certain template, this pages opened in more than 40 seconds and Tracy Debugger count more than 14000 pages loaded.
      When I look in the pages loaded list, I find a very large amount of lines that look like this:
      1247 /sc_admin/repeaters/for-field-182/for-page-1246/ Page 1248 /sc_admin/repeaters/for-field-158/for-page-1246/ Page 1249 /sc_admin/repeaters/for-field-159/for-page-1246/ Page 1250 /sc_admin/repeaters/for-field-169/for-page-1246/ Page 1251 /sc_admin/repeaters/for-field-170/for-page-1246/ Page 1252 /sc_admin/repeaters/for-field-180/for-page-1246/ Page 1254 /sc_admin/repeaters/for-field-137/for-page-1253/ Page 1256 /sc_admin/repeaters/for-field-182/for-page-1255/ Page 1258 /sc_admin/repeaters/for-field-170/for-page-1195/ Page 1261 /sc_admin/repeaters/for-field-182/for-page-1132/ Page 1262 /sc_admin/repeaters/for-field-159/for-page-1132/ Page 1263 /sc_admin/repeaters/for-field-169/for-page-1132/ Page 1264 /sc_admin/repeaters/for-field-170/for-page-1132/ Page 1265 /sc_admin/repeaters/for-field-180/for-page-1132/ Page Or other like :
      10222 /sc_admin/repeaters/for-field-138/for-page-5710/1623420295-8678-1/ RepeaterMatrixPage 10232 /sc_admin/repeaters/for-field-138/for-page-5710/1623420316-7346-1/ RepeaterMatrixPage 10242 /sc_admin/repeaters/for-field-138/for-page-5708/1623482402-7605-1/ RepeaterMatrixPage 10256 /sc_admin/repeaters/for-field-138/for-page-10254/1624257169-0968-1/ RepeaterMatrixPage 10266 /sc_admin/repeaters/for-field-138/for-page-10254/1624257191-2937-1/ RepeaterMatrixPage 10278 /sc_admin/repeaters/for-field-138/for-page-10254/1624257284-3093-1/ RepeaterMatrixPage 10289 /sc_admin/repeaters/for-field-138/for-page-10254/1624258816-4716-1/ RepeaterMatrixPage 10302 /sc_admin/repeaters/for-field-138/for-page-10254/1624259001-0062-1/ RepeaterMatrixPage 10312 /sc_admin/repeaters/for-field-138/for-page-10254/1624259056-5808-1/ RepeaterMatrixPage 10326 /sc_admin/repeaters/for-field-138/for-page-10254/1624259204-4337-1/ RepeaterMatrixPage 10336 /sc_admin/repeaters/for-field-138/for-page-10254/1624259240-545-1/ RepeaterMatrixPage 10347 /sc_admin/repeaters/for-field-138/for-page-10254/1624259280-7777-1/ RepeaterMatrixPage 10357 /sc_admin/repeaters/for-field-138/for-page-10254/1624259299-317-1/ RepeaterMatrixPage 10369 /sc_admin/repeaters/for-field-138/for-page-6006/1624259684-8705-1/ RepeaterMatrixPage 10381 /sc_admin/repeaters/for-field-138/for-page-10379/1624259765-4187-1/ RepeaterMatrixPage More than 10000...
      This template doesn't contain repeaterMatrix.
      How can I understand what's happened ?
      Thanks for your help
    • By Guy Incognito
      We have a client's Processwire site where the Pageimage::size() method has stopped working. It's creating small white PNGs in the assets folder instead of the resized image as usual.
      Their hosting was recently upgraded and switched to PHP 7.4 and I'm wondering if a they've removed a PHP package or changed a server config to cause this.
      Does anyone know if the image resizing functionality requires specific PHP modules I need to check for?
      I've checked the folder permissions on the server - this all looks fine.
      TIA,
      J
    • By Cesco
      Hi is possible to hide FieldsetTab if page has field set to certain value?
      It's possible for other field type by Input->Visibility->if... but not for FieldsetTab. 
      Thanks
      Francesco
×
×
  • Create New...