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

@Robin S
Thanks for pointing on this. I will make an update soon.

  • Like 1

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 2

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 Sten
      Sorry I can't find any submit button to save my configuration on a template in the admin interface. The file is fine.
    • By nabo
      Hello
      this is my snippet
      public function init() { if($this->wire('user')->isSuperuser()) { $this->wire()->addHookAfter('ProcessPageEdit::buildFormSettings', $this, 'buildForm'); $this->wire()->addHookBefore('ProcessPageEdit::processInput', $this, 'saveForm'); } } public function buildForm(HookEvent $event) { $p = $event->object->getPage(); $inputfields = $event->return; $fieldset = $this->wire('modules')->get("InputfieldFieldset"); $fieldset->attr('id', 'my_fieldset'); $fieldset->label = __("My Renders"); $fieldset->collapsed = Inputfield::collapsedYes; $field = $this->wire('modules')->get("InputfieldTextarea"); $field->attr('name', 'renders'); $field->attr('value', $p->renders); $field->label = $this->_('Renders'); $fieldset->append($field); $inputfields->append($fieldset); } public function saveForm($event) { $page = $this->pages->get($this->input->post->id); $page->set('renders', $this->input->post->renders); } It builds correctly the inputs, I edit the field renders but when I save the page the value of this inputfield remain blank.
      What's wrong?
    • By carlitoselmago
      I'm building a fieldtype/inputfield to visually select a grid like Bootstrap since it's the first time coding such thing, I'm basing my code in FieldtypeColorPicker since the base structure is the same, a graphical UI helper to finally output a string as value.
      The problem is I try to save the value as something like "1,2,3" referencing the index of each column selected but it gets converted as an int value so "1,2,3" becomes "1" if input random text it gets converted as "0".
      Here is the code:
      https://github.com/carlitoselmago/FieldtypeGridSpace
      Here's an screenshot of how it looks

    • By bramwolf
      Hi Guys,

      I found that my site is producing this notice on the front end, even when $config->debug = false and also when admin is
      not even logged in. How do I keep the site from displaying this message to front end users? The notice is about a few vars
      being tested, which in this case aren't defined, how would I stop that from happing all together when testing vars? if I for instance
      wrap the $discountCode = blabla in a if($order) { ...  } statement than I'm again testing for $order which isn't a object in this case
      which throws another notice..

      This is the notice:


      Here is my current code:
      // PAD DISCOUNT CODE HOOK // First we see if we have active discount code if ($this->session->orderId) { $order = $this->pages->get($this->session->orderId); } if($product->geen_korting == 1) { $nodisc = $product->geen_korting; } else { $nodisc = $product->parent->geen_korting; } $discountCode = $this->sanitizer->selectorValue($order->pad_discount_code); $dc = $this->pages->get("template=paddiscount, title=$discountCode"); if ($dc->id) { if ($nodisc) { $discount = 0; } elseif ($dc->pad_percentage) { $discount = $newprice * ($dc->pad_percentage / 100); } } $event->return = $newprice - $discount;
      Thanks in advance 🙂
    • By shadowkyogre
      [EDIT]: After sitting down and planning out my site according to the ragged hierarchy information, I settled on the following schematics.
      /$world/$template/$content_of_template_type/... for my pretty URLs /roster/$character for my characters a generic Repeater field with depth on most content types for custom positions for child pages to connect to instead of it directly a few Repeater fields on each content that have (PageReference[1], other fields) to establish associations A few FieldsetGroups to help me manage the fields that I needed to copy across a bunch of content types. Kept the original post below for context and tagged the OP for searchability.
      ---
      Hi everyone! I'm working on a personalized worldbuilding wiki to host my art and story stuff.
      Right now my site architecture looks like...
      /$world/cosmology/$cosmology /$world/locations/$location /$world/factions/$faction /$world/history/$history /$world/species/$species /roster/$character So far the layout works, but there's one problem. I need to make sub-sections for an organization. Organizations can appear under cosmology, locations, and factions. Sounds straightforward until... I run into the problem of figuring out how to represent subfactions.
      Key factors in this are...
      Characters should be able to be part of multiple organizations Characters should have an explicit role assigned to their membership. Character pages should be able to query the organization pages to display their ranks across organizations. Editing an organization's hierarchical layout should be visible while editing the root organization page. From what I've read of the ProcessWire documentation, the best use case for each way of representing the organization's subsections are...
      Child Pages:: Works best for menu presentation and dedicated editing. PageTables:: Works if you want control over where to place the PageTable fields, but requires opening a modal for the pages you want to edit. It's also kind of like normal pages. Repeaters:: Works great for inline editing and easy control over hierarchy, but the page urls become obscure. Sections in the body field:: Works for copypasting from my note files. But it doesn't expose relationships for easy querying. It looks like my best case for this is child pages since it allows displaying suborganization in the URL easily. But also I lose out on quickly reordering and editing the child pages. Any advice for people running into similar use cases?
×
×
  • Create New...