Giter Club home page Giter Club logo

fieldtypeimagereference's Introduction

FieldtypeImageReference & InputfieldImageReference

This module was renamed from the former ImagePicker Fieldtype and Inputfield. Due to the renaming, version v2.0.0 introduces breaking changes. If you have an older version already installed, you need to uninstall it first and then install v2.0.0

Fieldtype Image Reference is a Fieldtype that stores a reference to a single image from

  • from a folder inside site/templates/
  • from any page on the site.

The image can be selected with the associated Inputfield.

Inputfield Image Reference is an Inputfield to select a single image from

  • images on another page and optionally its children
  • and/or from a folder inside site/templates/ or site/assets/
  • and/or from the page that is being edited
  • and/or from any page on the site

Inputfield in page edior You can upload/edit images to other pages from within the input field Upload images to other pages from within field

When to use ?

If you want to let editors choose an image from a set of images that is being used site-wide. Ideal for images that are being re-used across the site (e.g. icons, but not limited to that). If you want to manage (upload/delete) images inside a folder that do not belong to a single page. Other than the native ProcessWire images field, the images here are not stored per page. Only references to images that live on other pages or inside a folder are stored. This has several advantages:

  • one central place to organize images
  • when images change, you only have to update them in one place. All references will be updated, too. (Provided the name of the image that has changed stays the same)

Features

  • Images can be loaded from a folder inside site/templates/ or site/assets
  • Images in that folder can be uploaded and deleted from the inputfield
  • Images can be loaded from other pages defined as image source
  • Images can be organized into categories. Child pages of the main 'image source page' serve as categories
  • Images can be loaded from any page on the site
  • From the API side, images can be manipulated like native ProcessWire images (resizing, cropping etc.), even the images from a folder
  • Image thumbnails are loaded into inputfield by ajax on demand
  • Markup of SVG images can be rendered inline with echo $image->svgcontent
  • Image names are fully searchable through the API
$pages->find('fieldname.filename=xyz.png');
$pages->find('fieldname.filename%=xy.png');
  • Accidental image deletion is prevented. When you want to delete an image from one of the pages that hold your site-wide images, the module searches all pages that use that image. If any page contains a reference to the image you are trying to delete, deletion will be prevented. You will get an error message with links to help you edit those pages and remove references there before you can finally delete the image.
  • This field type can be used with marcrura's Settings Factory module to store images on settings pages, which was not possible with other image field types

Settings / Options

  • The page containing the images to choose from.
    • Images from that page and optionally it's child pages will be used as site-wide images.
  • Option to include images from child pages of the page above
  • A folder containing the images to choose from
    • Image extensions and max file size for images in folder
  • Option to also include the images from the page being edited
  • Option to choose images from any page on the site
  • The image fields to use. These fields will supply images to the image reference field
  • Width of chosen image in Inputfield.
  • Width of image thumbnails in Inputfield.

Inputfield Settings

All settings are per field that you create from this fieldtype. This means you can have different images to choose from for different fields that you create.

How to install and setup

  1. Download and install or install from URL the module like any other modules in ProcessWire
  2. Optional: create a page in the page tree that will hold your images and supply them to the inputfield. This page's template must have an images field
  3. Optional: upload some images to the page you created in step 2
  4. Optional: upload images to a folder inside site/templates
  5. Create a new field. As type choose 'Image Reference'. Save the field.
  6. Optional: in 'Details' Tab of the field choose the page you created in step 2
  7. Optional: click Save button
  8. Optional: click Save button again
  9. Optional: upload images to a folder inside site/templates/ or site/assets/
  10. Optional: choose to use that folder as image source
  11. Optional: choose whether you want to include child pages of page from step 2 to supply images
  12. Optional: choose whether you want to include images from the page being edited
  13. Optional: choose images from any page of the site
  14. Optional: choose the images field names of the fields that supply images
  15. Add the field to any template
  16. You are now ready to use the field

Permissions

The module installs 2 permissions:

  • imagereference-folder-upload
  • imagereference-folder-delete

If you want non-superusers to be able to upload and delete images in folders, you need to assign those permissions to their roles.

How to use in template files

// render image 
<img src="<?= $page->fieldname->url ?>"> 
// all native ProcessWIre image manipulation methods (resizing, cropping etc.) are available
$thumb = $page->fieldname->width(100);
// render the text content for inlining SVG (works only with SVG images)
$page->fieldname->svgcontent
// search pages with image by file name or page id of the source page
$pages->find('fieldname.filename=xyz.png');
$pages->find('fieldname.pageid=1234');
// set image via API
$p = $pages->get(1001);
$image = $p->image; // returns a Pageimage object
$p->of(false);
$p->set('imagereference', $image); // sets the Pageimage object to the ImageReference field. This gets converted to a JSON string internally for storage
$p->save();

Requirements

  • Processwire >= 3.0.120
  • PHP >= 7.1

Credits

This module was developed based on ideas from forum members in this forum thread

Roadmap

  • allow to choose multiple images

fieldtypeimagereference's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

esszett

fieldtypeimagereference's Issues

Missing responsive image thumbnail preview

The preview image is set by default to 200px or 100px but isn't responsive. When it falls on template's fields layout where container is pretty narrow (20/30%) the image doesn't fit the space by resizeing itself but goes outside the boundaries.

imageexternalreference

It would be great if it could responsively adapt to its container.

BTW, great work. Can't wait its supporting for multiple images. Now I'm using repeaters for galleries but with that change will be a charm to build image galleries.

Cannot access protected property ProcessWire\Pageimage::$original

Hi, thanks for the module. When I select an image from a predefined folder, after save, I get:

Cannot access protected property ProcessWire\Pageimage::$original in /wire/core/PageimageVariations.php:256

PHP Notice: Undefined property: ProcessWire\PageimageDebugInfo::$original in ...\wwwroot\wire\core\PageimageDebugInfo.php:71

It might be related to PHP 7.4 or might be something with my installation or other hooks. I can't provide more info right now but will dig into this later.

edit: it's better if I set 'allowSelf' => false in populateImages(), but after every page refresh, new variations are created...strange

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.