All Projects → olach → Kirby Relationship

olach / Kirby Relationship

Sortable multiselect field for Kirby 2 CMS

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Kirby Relationship

Kirby Pay
Make online payments with Kirby
Stars: ✭ 27 (-65.38%)
Mutual labels:  kirby
React Sortablejs
A React component built on top of the mature drag and drop library, Sortable.
Stars: ✭ 1,052 (+1248.72%)
Mutual labels:  sortable
Vue Smooth Dnd
Vue wrapper components for smooth-dnd
Stars: ✭ 1,121 (+1337.18%)
Mutual labels:  sortable
Kirby Template Sitemap
DEPRECATED: Sitemap-Templates with option to exclude pages by template e.g. for one-pagers
Stars: ✭ 9 (-88.46%)
Mutual labels:  kirby
Select A Structure
A select field for Kirby populated by a structure field.
Stars: ✭ 44 (-43.59%)
Mutual labels:  kirby
Kirby Geolocation Field
Geolocation panel field for Kirby 2
Stars: ✭ 52 (-33.33%)
Mutual labels:  kirby
Dragact
a dragger layout system with React style .
Stars: ✭ 710 (+810.26%)
Mutual labels:  sortable
Embed
Media embed plugin for Kirby 2 CMS
Stars: ✭ 73 (-6.41%)
Mutual labels:  kirby
Kirby Color Palette
A color palette to pick colors from in the panel. Kirby 3 only.
Stars: ✭ 47 (-39.74%)
Mutual labels:  kirby
Sirvy
🔗 Kirby Services API
Stars: ✭ 59 (-24.36%)
Mutual labels:  kirby
Elementui Multiselect
基于element ui、vue的多选框,支持选项disabled,支持分页,输入框过滤,可显示或隐藏全选和清空项
Stars: ✭ 14 (-82.05%)
Mutual labels:  multiselect
Kirby Autofocus
Content aware image cropping for Kirby. Kirby 2 and 3.
Stars: ✭ 35 (-55.13%)
Mutual labels:  kirby
Yii2 Sortable Widgets
🍨 Rubaxa/Sortable for Yii2
Stars: ✭ 54 (-30.77%)
Mutual labels:  sortable
Kirby Sri
Subresource integrity hashing & cache-busting static assets for Kirby
Stars: ✭ 9 (-88.46%)
Mutual labels:  kirby
Kirby Tablex
KIRBY 2 ONLY. No plans for K3 version yet. Table field for Kirby CMS.
Stars: ✭ 70 (-10.26%)
Mutual labels:  kirby
Bentobox
A simple theme to organize links using the Kirby CMS
Stars: ✭ 24 (-69.23%)
Mutual labels:  kirby
React Movable
🔀 Drag and drop for your React lists and tables. Accessible. Tiny.
Stars: ✭ 1,064 (+1264.1%)
Mutual labels:  sortable
Kirby Calendar Plugin
A plugin for the Kirby CMS to easily implement an event calendar.
Stars: ✭ 76 (-2.56%)
Mutual labels:  kirby
Panel Bar
panelBar for Kirby 2 CMS
Stars: ✭ 70 (-10.26%)
Mutual labels:  kirby
Getkirby.com
Source code and content for the Kirby website
Stars: ✭ 57 (-26.92%)
Mutual labels:  kirby

Kirby Relationship field

Latest version License Required Kirby version

The Relationship field allows you to select and sort multiple items from a list. Think of it as a sortable multiselect field or a sortable checkboxes field.

relationship-field-demo

This plugin is free to use. But if you find it helpful, feel free to buy me a coffee ☕️.

Requirements

This field has been tested with Kirby 2.5+, but it should probably work with earlier versions too.

Looking for a version compatible with Kirby 3? A new version is currently in development.

Installation

Manually

Download the files and place them inside site/fields/relationship/.

With Kirby CLI

Kirby's command line interface makes the installation really simple:

$ kirby plugin:install olach/kirby-relationship

Updating is also easy:

$ kirby plugin:update olach/kirby-relationship

Usage

The field is an extension of the Checkboxes field. All options of that field apply to this field too. The data is saved as a comma separated string, which means that this field is interchangeable with the Checkboxes field.

Example with predefined options

Blueprint

countries:
  label: Countries
  type: relationship
  options:
    sweden: Sweden
    norway: Norway
    denmark: Denmark
    finland: Finland
    iceland: Iceland
    germany: Germany
    france: France
    spain: Spain
    portugal: Portugal

Template

<ul>
  <?php foreach ($page->countries()->split() as $country): ?>
  <li><?= $country ?></li>
  <?php endforeach ?>
</ul>

Example with related pages

Blueprint

related:
  label: Related articles
  type: relationship
  options: query
  query:
    fetch: siblings

Template

<h2>Related articles</h2>
<ul>
  <?php foreach ($page->related()->pages(',') as $related): ?>
  <li>
    <a href="<?php echo $related->url() ?>">
      <?= $related->title() ?>
    </a>
  </li>
  <?php endforeach ?>
</ul>

Features

Search:

To enable search, add search: true to the field settings in your blueprint.

related:
  label: Related articles
  type: relationship
  options: query
  query:
    fetch: siblings
  search: true

Min and max items:

You can control the minimum number of required items and the maximum number of allowed items. Don't forget to add a help text to inform the editor about the requirements.

related:
  label: Related articles
  type: relationship
  options: query
  query:
    fetch: siblings
  search: true
  min: 3
  max: 6
  help: Select from 3 up to 6 articles.

Counter indicator

A handy indicator of the current amount of selected items can be displayed in the upper right corner with the option counter. This indicator is always shown when the min/max option is active, but can be disabled by setting its value to false.

related:
  label: Related articles
  type: relationship
  options: query
  query:
    fetch: siblings
  search: true
  counter: true

Controller:

This field is extended with an option to use a user specified function to have even more control of the options that will be loaded. The idea is taken from the Controlled List plugin.

Example

Create a simple plugin that lets you choose from the panel users.

site/plugins/myplugin/myplugin.php:

class MyPlugin {
  static function userlist($field) {
    $kirby = kirby();
    $site = $kirby->site();
    $users = $site->users();

    $result = array();

    foreach ($users as $user) {
      if (!empty($user->firstName()) && !empty($user->lastName())) {
        $result[$user->username()] = $user->firstName() . ' ' . $user->lastName();
      } else {
        $result[$user->username()] = $user->username();
      }
    }

    return $result;
  }
}

In your blueprint:

users:
  label: Users
  type: relationship
  controller: MyPlugin::userlist

Thumbnails:

It's possible to show a small thumbnail for each list item. There are three different ways to do this:

Options list

Manually specify a set of URLs pointing to images to be used as thumbnails.

No downscaling is performed here, the images are used as is. So be kind to your users and don't link to high resolution images.

countries:
  label: Countries
  type: relationship
  options:
    sweden: Sweden
    norway: Norway
    denmark: Denmark
    finland: Finland
    iceland: Iceland
    germany: Germany
    france: France
    spain: Spain
    portugal: Portugal
  thumbs:
    options:
      sweden: /assets/images/flag-sweden.png
      norway: /assets/images/flag-norway.png
      denmark: /assets/images/flag-denmark.png
      finland: /assets/images/flag-finland.png
      iceland: /assets/images/flag-iceland.png
      germany: /assets/images/flag-germany.png
      france: /assets/images/flag-france.png
      spain: /assets/images/flag-spain.png
      portugal: /assets/images/flag-portugal.png

Image field

By specifying the field name of an image field, the thumbnails can be fetched automatically. This requires that the list items are regular pages with an image field specified. Also, make sure that the value attribute used are page URIs.

The images are shown downscaled. The default thumbnail size of the panel is used, so no additional thumbnail generation is being done.

related:
  label: Related articles
  type: relationship
  options: query
  query:
    fetch: siblings
    value: '{{uri}}'
  thumbs:
    field: featured_image

Thumbnails controller

For full control, you can specify a user specified function to be used for the thumbnails. The function needs to return a URL to an image.

The following example extends the previous panel users example by showing their avatars as thumbnails.

site/plugins/myplugin/myplugin.php:

class MyPlugin {
  static function userlist($field) {
    $kirby = kirby();
    $site = $kirby->site();
    $users = $site->users();

    $result = array();

    foreach ($users as $user) {
      if (!empty($user->firstName()) && !empty($user->lastName())) {
        $result[$user->username()] = $user->firstName() . ' ' . $user->lastName();
      } else {
        $result[$user->username()] = $user->username();
      }
    }

    return $result;
  }

  static function useravatar($key, $field) {
    $kirby = kirby();
    $site = $kirby->site();

    $url = '';

    if ($avatar = $site->user($key)->avatar()):
      $url = $avatar->crop(75)->url();
    endif;

    return $url;
  }
}

In your blueprint:

users:
  label: Users
  type: relationship
  controller: MyPlugin::userlist
  thumbs:
    controller: MyPlugin::useravatar

Keyboard navigation:

The field is keyboard accessible. Press tab and shift + tab to give focus to the lists. Within a list, use the arrow keys to navigate and press space to select/deselect an item. In the sortable list, you can sort the items by selecting an item with space and then move the item using the arrow keys.

Version history

You can find the version history in the changelog.

License

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].