Jump to content
Mikel

fieldtype for storing image reference

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?

Share this post


Link to post
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?)

Share this post


Link to post
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

Share this post


Link to post
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. 

Share this post


Link to post
Share on other sites

The function filter() is hookable. You can modify the selector string returned by filter().

  • Like 2

Share this post


Link to post
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

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

Drop the code in a file ready.php and place it in your /site/ folder.

  • Like 1

Share this post


Link to post
Share on other sites

OMG! Of course, I forgot about this possibility)

Thank you, this works perfectly!

  • Like 1

Share this post


Link to post
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)?

Share this post


Link to post
Share on other sites

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?

 

Share this post


Link to post
Share on other sites

@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

Share this post


Link to post
Share on other sites

@horst - I haven't tried this, but this Inputfield module might work for you?  Looks like it can show a thumbnail preview image.

 

  • Like 1

Share this post


Link to post
Share on other sites

@gmclelland many thanks.  Will have alook at it. Meanwhile I had solved it with bitpoets medialibrary (and maybe something other in combination? Don‘t remember correct atm.)

Share this post


Link to post
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 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By LuisM
      Hi there,
      im a bit lost right now. I added an hook after templates::save which should get the affected template and write its template ID into a JSON.
      The problem is, the event->object gives me an instance of the templates class. How can I narrow this down to the saved Template and get its ID and fieldgroup?
    • By Clément Lambelet
      Hey!
      I've been working on a Processwire installation (3.0.123) for a few days now and I must have made a big mistake this morning because the links in the admin's main menu no longer appear.
      This is not related to the admin theme, because the bug occurs with all themes (Default, Reno, Uikit).
      I tried to reinstall with the dev version (3.0.136), but the problem is still there. I also uninstalled all the modules I had added, without success. There is no error in the js console. 
      I still can access/view/edit the pages  by going through the admin/page list.
      Thanks in advance for your help!


    • By lecrackffm
      Hey all,
      i do, most probably have a problem with file encoding and / or BOM. 
      My <head>  content is getting moved into <body> and i can inspect a couple of &#65279;  ( ZERO WIDTH NO-BREAK SPACE) chars with dev tools.
      I checked all template files with phpstorm, they are all in utf-8 w/o BOM.
      The current installation is based on a profile i exported from another project where i had not such problems.
      However, in the new project i did change the default language to german and installed english as the second language. 
      Might there be any conflicts with the language support modules?
      Hints, tips or solutions are highly appreciated 🙂
    • By pwFoo
      Hi,
      I try to add page-edit-own and page-delete-own permissions, but it's strange...
      If a add the custom permissions it looks like both are children of page-edit respectively page-delete. I played with added / revoked permissions, but I can't get it work, that a user of a role just can delete own content.
      First the user can't delete any content and now the user can delete own and foreign pages 🤪
      Is there a tutorial to learn more about the PW permissions?
      Or do I have to rename the permissions to page-own-edit and page-own-delete to be independent from page-edit and page-delete?
    • By pwFoo
      I tried to add a new page with $pages->add() with a custom method inside of a module. It looks like the method is called each page load (as should) and also if the backend page tree is loaded / refreshed (bug??)?
      public function create($template, $parent, Array $data = array(), $name = false) { $name = wire('sanitizer')->pageName($name ? $name : $data['title']); $obj = wire('pages')->add($template, $parent, $name, $data); return $obj; } called inside of home page ("/"):
      $api->create('basic-page', '/', array('title' => 'ApiCreatedTest1')); Works fine. Load it twice (create duplicate page) results in an error.
       
      But without "/" requested the page gets created if I view the backend?!
      Checked it by delete the page, check the page tree again and it looks fine. But if I reload the backend page the page appears again. So backend page tree load executes the home page ("/") and create the page?
      Is it a bug or I'm missing anything...?
×
×
  • Create New...