GithubHelp home page GithubHelp logo

storypioneers / kirby-selector Goto Github PK

View Code? Open in Web Editor NEW
128.0 17.0 23.0 349 KB

file selector panel field for Kirby CMS

License: GNU General Public License v3.0

CSS 6.51% PHP 66.15% JavaScript 26.27% Shell 1.07%

kirby-selector's Introduction

Selector – Kirby Fileselect Field

This additional panel field for Kirby 2 allows you to use an intuitive alternative file selection field in your blueprints.

Authors: digital storytelling pioneers feat. Jonas Doebertin

License: GNU GPL v3.0

Screenshot

Installation

Copy or link the selector directory to site/plugins/ or use the Kirby CLI kirby plugin:install storypioneers/kirby-selector.

Usage

Within your blueprints

Post installation simply add selector fields to your blueprints and set some options (where applicable).

fields:
	postimage:
		label: Main Post Image
		type:  selector
		mode:  single
		types:
			- image
fields:
	attachments:
		label: Post Attachments
		type:  selector
		mode:  multiple
		types:
			- all

Within your templates / controllers / models

As per design, the selector field stores the filenames of the selected files, only. If you need access to the files full path or to other properties / functions of the file object, you must convert the filename into a full file object first.

Single Mode

When you're using the Selector field in Single Mode, gaining access to the full file object is quite easy. Just replace yourselectorfield with the name of your Selector-based field.

	// Convert the filename to a full file object
	$file = $page->yourselectorfield()->toFile();

	// Use the file object
	echo $file->url();

Multiple Mode

In multiple mode, the Selector field stores a comma-separated list of filenames, based on how many files you selected. To convert this list into a fully-featured file collection (just like $page->files()), you need a bit more code.

	// Transform the comma-separated list of filenames into a file collection
	$filenames = $page->yourselectorfield()->split(',');
	if(count($filenames) < 2) $filenames = array_pad($filenames, 2, '');
	$files = call_user_func_array(array($page->files(), 'find'), $filenames);

	// Use the file collection
	foreach($files as $file)
	{
		echo $file->url();
	}

Options

The field offers some options that can be set on a per field basis directly from your blueprints.

mode

Define a mode the field will work in. Possible values are single and multiple.

  • single: With the single mode, the fields checkboxes will work like a set of radio buttons, letting you select a single file only. This is useful if you want a way to specify a posts main image.

  • multiple: This option allows you to select multiple files in a single file selector field. The selected files will be stored as a comma separated list.

types

Define the files types the file selector field shows. Possible values are all, image, video, audio, document, archive, code, unknown. You may specify as many of these types as you like.

fields:
	attachments:
		label: Post Attachments
		type:  selector
		mode:  multiple
		types:
			- image
			- video
			- audio
			- document

sort

Files will be shown sorted by their filename in ascending order (a-z). However, this option let's you change the default sort behavior. You can sort files by filesize, dimensions, type and many more. Some of the countless possible values are sort, filename, size, width, height, type, modified, ratio. You can also sort by any of your custom file fields. The value sort will make sure the files are presented in the exact order you specified in the panels file section via drag and drop.

fields:
	featured:
		label: Featured Image
		type:  selector
		mode:  single
		sort:  size
		types:
			- image

flip

This options allows you to reverse the sort order you specified with the sort option. You may set this to true or false.

autoselect

This options allows you to tell the Selector to auto select the first, last or all files of the list, if no other file is selected, yet. Possible values are none (default), first, last and all.

fields:
	featured:
		label:      Featured Image
		type:       selector
		mode:       single
		sort:       filename
		autoselect: first
		types:
			- image

filter

This options allows you to set a filename filter. This can be either a simple string or a fully featured regular expression. Only files with filenames matching the filter string or regular expression will be shown in the Selector field. You may set this to any string like background, .min.js or large or a regular expression like /\.((png)|(jpe?g))/i.

fields:
	featured:
		label:  Page Background Image
		type:   selector
		mode:   single
		filter: background
		types:
			- image

Showing only image files with the term background in their filename.

fields:
	featured:
		label:  Page Background Image
		type:   selector
		mode:   single
		filter: /\.((png)|(jpe?g))/i

Using a regular expression to show only .jpg, .jpeg and .png files.

size

The size option lets you limit the height of the selector field and makes it scrollable. Only the specified number of files will be shown initially. This can be set either to a number or to auto (the Selector field will adapt to the height of the complete list of files).

fields:
	featured:
		label: Page Background Image
		type:  selector
		mode:  single
		size:  4

kirby-selector's People

Contributors

amustill avatar dgdsp avatar jonasdoebertin avatar medienbaecker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kirby-selector's Issues

Plugin not working in structure Kirby 2.2.1

Hi,

I just installed kirby 2.2.1 but it seems the selector plugin isn't working properly in a structured field. The add and edit button don't do anything when you click them.

Field in Plugin Folder is not working in Kirby 2.4.0

The selector field does not get initialized properly when I add it as a submodule to the plugins folder. It only works if I copy and rename the site/plugins/selector/field folder from the directory to site/fields/selector.

Somehow $kirby->set('field', 'selector', __DIR__ . DS . 'field'); doesn't get recognized.

Fatal error: Cannot access protected property SelectorField::$types

This issue appears only on the live site and not in my local version (see screenshots below). I'm running Kirby 2.1 and as a solution have updated both Kirby and Selector to the latest versions. Still not working.

Below is the blueprint. Thanks for the help!

<?php if(!defined('KIRBY')) exit ?>

title: Team Member
pages: false
files: false
fields:
  title:
    label: Name
    type:  text
  text:
    label: Bio
    type:  textarea
  postimage:
    label: Main Post Image
    type:  selector
    mode:  single
    types:
      - image
  role:
    label: Role
    type:  text
    icon: video-camera

Error on live site

live_site

Working well on local site

local_site

Issue with protected variable on php 5.3.3.

Had a problem using the kirby-selector on php 5.3.3. with line 335-338 in selector.php:

$files = $files->sortBy($this->sort, ($this->flip) ? 'desc' : 'asc')
    ->filter(function($file) use($field) {
        return $field->includeAllFiles() or in_array($file->type(), $field->types);
    });

Setting the $types variable in selector.php on line 70 from protected to public solves the problem and prevents kirby-selector from crashing the panel. Haven’t looked into it further yet but there must be a more elegant way to solve it.

Unselect in single mode

It's not possible to unselect a selected item in single mode.

I've added this code to selector.js to enable this feature:

/*
    SINGLE MODE
    Unselect all items and reselect only the curent one.
 */
if(self.mode == 'single') {
    if($target.data('checked') == 'true') {
        self.setUnselectedStates();
    } else {
        self.setUnselectedStates();
        self.setSelectedState($target);
    }
}

Works Kirby-Selector with Kirbybuilder

Hi,
does anybody know if that plugin will work together with the KirbyBuilder?
I read this here on the Kirbybuilder page which it makes me thoughtful:

All issues related to the structure field of Kirby Panel do also affect the builder field. Builder fields do not support nested fields that require a modal to handle the content, i.e. structure fields or other builder fields.

Kind

The selector field is missing.

Hi there.

I moved the plugin from /site/fields to /site/plugins … now I m getting the following error message:

The selector field is missing. Please add it to your installed fields or remove it from your blueprint

Issue with large files

After uploading a big image (3.5 MB), and using the autoselect option, the selector field and everything located under it disappear, including the save button. The problem persists until I delete the image.

Use a source of files other than the current page

Use case: I'd like to use the $site collection of files as the source for the selector, so that I can share the same selection of images across many content pages, without needing duplicate files on each page.

I think I can hack the files() function for my purposes, but not nicely enough for PR, so suggesting this as a possible enhancement.

In fact, it might also be useful to set the source from another specified page, i.e. something blueprinty like:
source: page (default) | site | content/uri

Files sorting not working

Currently it's not possible to get the files in the multiple field mode in the same order as in the page object.

This is the code to get that behaviour (selector.php on line 177):

return $this->page()->files()->sortBy('sort', 'asc')->filter(function($file) use ($field) {
 return $field->includeAllFiles() or in_array($file->type(), $field->types);
});

Sort: Display selected images on top

When loading the page, or after saving, it would be nice to have the selected file(s) be floated to the top of the list.

I'm currently a single row selector to choose a thumbnail image, but with a long list of images the user does not immediately know which one is selected. Though I'm not currently using the sort feature, this may be nice as an additional param in order to not interfere with the other sort options.

Install plugin via Kirby CLI

It would be nice to be able to install this plugin via the Kirby CLI.

A package.json file will need to be added to this project with "type": "kirby-field" set.

The install command would then be

kirby plugin:install storypioneers/kirby-selector

Not working for Site blueprint

I'm getting this:

Fatal error: Call to a member function files() on null in /Users/Joseph/Sites/d17/site/fields/selector/selector.php on line 251

When I try to use the selector on the site.txt blueprint.

"Notice: Array to string conversion" when value is not setted

I had a "Notice: Array to string conversion" when I used the plugin for the first time, I had find a simple solution changing the template.php:

<input class="[ js-selector-storage ]" type="hidden" name="<?= $field->name() ?>" id="<?= $field->name() ?>" value="<?= $field->value() ?>" />

for

<input class="[ js-selector-storage ]" type="hidden" name="<?= $field->name() ?>" id="<?= $field->name() ?>" value="<?php if(!empty($field->value())) echo implode(",",$field->value()) ?>" />

;)

Not outputting full url when used on homepage

Ran into a weird problem, the $page->foo()->url() doesn't return the full url on the homepage, but works fine on all other templates.

Using this code in home.php:

    <?php if ($page->background()): ?>
        <img src="<?php echo $page->background()->url() ?>"  />
    <?php endif ?>

It will just output

     <img src="background.jpg" />

Add option to select source for files

Would it be possible to add an option which would filter the available files to a particular source, eg:

  • the new global site files
  • a different page to the current page
  • a set of pages (siblings perhaps)

As a use case, let's say you have collection of different banner images in the site section which are available from every page using the site file method. Then on each new page, you use the Selector field to show all the available banner images so that the user can select which one to use on this page.

This plugin is an extremely useful tool and I would hope something like the above would be a useful addition. Thanks for your consideration!

Get the imageurl inside an structurefield

Hi,
If I use your selectorfield inside an structurefield. How can get the imageurl?
If I do it like in the documentation I have to break the foreach.
What can I do?

Kind regards

Migrate to kirby 3

I really liked this plugin for kirby 2, do you plan to migrate it for kirby 3?

.png images

If i have a .png image among the files in my page, the plugin brakes the form. I attach a visual example of the problem, the blueprint structure is the following:

<?php if(!defined('KIRBY')) exit ?>

title: About
pages: false
files: true
fields:
  title:
    label: Title
    type: text
  name:
    label: Name
    type:  text
  profile_image:
    label: Profile Image
    type: selector
    mode: single
    types:
      - image

schermata 2015-06-22 alle 18 14 02

Adding file from Structure field doesn't work

On latest version of Kirby.

Steps to reproduce:

  1. Open the edit popup for a structure field
  2. Click +Add for the selector field
  3. Observe that the structure popup closes

Good news is I am able to select files that have already been added to the page using the Files sidebar, and save them successfully. But it'd be nice not to have to explain to the client that the +Add button there is buggy.

Selector not working at all

Hi – I'd love to get Selector up and running but having a major issue – I install as required (site/fields/selector/ etc.) and add the correct guff to my blueprint (copy and paste from Selector git page) but when I browse through Panel to an affected page I get this:
The localhost page isn’t working
localhost is currently unable to handle this request.
HTTP ERROR 500

I'm running this locally (obviously) via mamp. Any ideas where to go from here?
Thanks.

Issue using `single` mode

When I am using your selector in single mode. There is an issue when I drag and drop an image from the Files section to your Main Image form field. When I do this, any unsaved changes that I have made to the other fields dissappear.

Oh yeah. I love this by the way! Great job!

Selector not working in home blueprint

Hi there,

I'm working on integrating the Selector for an image rotator that appears on the home page. I have Selector configured beautifully for other photo galleries on my event pages, that works perfectly. But when I try to add Selector to my home page, it simply does not work- the page is blank.

Here is the working photo gallery:

gallery:
        label: Gallery Images
        type:  selector
        mode:  multiple
        types:
            - image

But this is what is not working on the home.php blueprint:

  postimage:
        label: Main Post Image
        type:  selector
        mode:  multiple
        types: 
            - image

When it shows the Selector, it says there are no valid image files- but I have 70 stored in my home page's content folder! Do you know why it is not working? Thanks for your help!

Readme install instructions need clarification

I'm new to Kirby so that might be half of it, but I'm having trouble understanding how to get this working.

The install instructions say:

Copy or link the selector directory to site/plugins/

But there's no directory called 'selector'. I think you just mean to drop the entire contents of the repo in a directory inside site/plugins ? When I install with kirby-cli, it does this into a site/plugins/field-selector.

Then in the blueprints instructions, it goes on to say:

As soon as you dropped the field extension into your fields folder

Do I need to move something into another directory for this to work? Which plugin directory into where?

Thanks!

Call to undefined method: panel()->language()

First of all: Thanks for the great plugin!

With the latest files from the dev-branch of kirby I get the following error:

Fatal error: Call to undefined method Kirby\Panel::language() in … site/fields/selector/selector.php on line 148

return 'de' or 'en' manually works fine.

Not Working

Whenever I load a page with the selector field I get the following warnings:

Warning: Illegal string offset 'name' in /Applications/XAMPP/xamppfiles/htdocs/projects/wilshire-skyline/panel/app/lib/blueprint/fields.php on line 16
Warning: Illegal string offset 'page' in /Applications/XAMPP/xamppfiles/htdocs/projects/wilshire-skyline/panel/app/lib/blueprint/fields.php on line 17
Warning: Illegal string offset 'type' in /Applications/XAMPP/xamppfiles/htdocs/projects/wilshire-skyline/panel/app/lib/blueprint/field.php on line 29
Warning: Illegal string offset 'default' in /Applications/XAMPP/xamppfiles/htdocs/projects/wilshire-skyline/panel/app/lib/blueprint/field.php on line 33
Warning: Invalid argument supplied for foreach() in /Applications/XAMPP/xamppfiles/htdocs/projects/wilshire-skyline/kirby/toolkit/lib/obj.php on line 17
Warning: Illegal string offset 'name' in /Applications/XAMPP/xamppfiles/htdocs/projects/wilshire-skyline/panel/app/lib/blueprint/fields.php on line 16
Warning: Illegal string offset 'page' in /Applications/XAMPP/xamppfiles/htdocs/projects/wilshire-skyline/panel/app/lib/blueprint/fields.php on line 17
Warning: Illegal string offset 'type' in /Applications/XAMPP/xamppfiles/htdocs/projects/wilshire-skyline/panel/app/lib/blueprint/field.php on line 29
Warning: Illegal string offset 'default' in /Applications/XAMPP/xamppfiles/htdocs/projects/wilshire-skyline/panel/app/lib/blueprint/field.php on line 33
Warning: Invalid argument supplied for foreach() in /Applications/XAMPP/xamppfiles/htdocs/projects/wilshire-skyline/kirby/toolkit/lib/obj.php on line 17
Warning: Missing argument 1 for FieldAbstract::__construct(), called in /Applications/XAMPP/xamppfiles/htdocs/projects/wilshire-skyline/panel/app/lib/form.php on line 240 and defined in /Applications/XAMPP/xamppfiles/htdocs/projects/wilshire-skyline/kirby/core/field.php on line 20
Warning: Missing argument 2 for FieldAbstract::__construct(), called in /Applications/XAMPP/xamppfiles/htdocs/projects/wilshire-skyline/panel/app/lib/form.php on line 240 and defined in /Applications/XAMPP/xamppfiles/htdocs/projects/wilshire-skyline/kirby/core/field.php on line 20
Notice: Undefined variable: page in /Applications/XAMPP/xamppfiles/htdocs/projects/wilshire-skyline/kirby/core/field.php on line 21
Notice: Undefined variable: key in /Applications/XAMPP/xamppfiles/htdocs/projects/wilshire-skyline/kirby/core/field.php on line 22

Is there a way to turn down the level for error reporting? Or am I doing something wrong? My blueprint looks like this:

<? if(!defined('KIRBY')) exit ?>

title: Hero
pages: false
files: true
fields:
  title:
    label: Page Title
    type:  text
  bgi:
    label: Post Attachments
    type:  selector
    mode:  multiple
    types:
      - all
  width:
    label: Width
    type: select
    options:
      so-on : So Forth

My system details are as follows:

  • running Kirby 2.0.1
  • selector plugin installed as a git submodule
  • have a few other fields installed too:

Option to specify a set maximum number of selections

I want to restrict the number of items that can be selected - Solving a cover-slideshow situation, where a client might chose ~15 humongous photos of mobile destruction 🙈

The output could of cause just be chopped at X items in the template -but limiting the number at the selection process would be more elegant, in my opinion.

Filter by filename

Luke wrote:

It appears to work great. My one thought would be a feature addition, the ability to filter the results by file name as well.

If I wanted to use this for a featured image, a background image, etc within the same page I could then filter it by images that include a "bg" or "background" prefix in the file name. It's a nit pick sort of thing, but this way you're not seeing image repetition.

http://forum.getkirby.com/t/visual-file-select-panel-field-extension/397/8?u=dieserjonas

Performance Issues - Pagination?

I am working on a website for my local climbing club. They now have the possibility to create image galleries and use that extensively - some pages host over 300 pictures now!

Unfortunately that means that the performance of the page load is quite poor. Swapping kirby-selector for a normal select-field reduces the page load by more than 5 seconds! I realise that your plugin is way more complex than a simple select field and will probably never be equally fast.

I think added pagination/lazy loading could help minimize the issue. Is that something you would be willing to explore or am I alone with this issue?

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.