Code Monkey home page Code Monkey logo

entry_relationship_field's Introduction

Entry Relationship Field Scrutinizer Code Quality

A new way to create master-details (parent -> children) relationships with Symphony's sections.

SPECS

  • Supports multiple sections for the same relationship.
  • Offers developers the possibility to create xslt templates for the field's backend UI.
  • Offers a modal UI in order to create/edit for the children.
  • Compatible with Symphony associations.
  • Supports multiple level (recursive) of associations.
  • Aims to be compatible with all fields.

REQUIREMENTS

  • Symphony CMS version 2.7.3 and up (as of the day of the last release of this extension)

INSTALLATION

  • git clone / download and unpack the tarball file
  • Put into the extension directory
  • Enable/install just like any other extension

You can also install it using the extension downloader. Just search for entry_relationship_field.

For more information, see http://getsymphony.com/learn/tasks/view/install-an-extension/

UPDATE FROM 1.0.x

Some developers may have been relying on some bugs in the xslt templates which may break when updating from versions before 2.0.0. In fact, under some circumstance, the field would output only their default mode instead of all of them. If this is the case, your either have to be more precise in your XPath queries or in the field's includable elements.

HOW TO USE

  • Go to the section editor and add an Entry Relationship field.
  • Give it a name.
  • Select at least one section that will be permitted as children.
  • Select also the fields you want to be available in the backend templates and data sources.
    • x- prefixed attributes are only available in devkit mode.
  • Create backend templates in the workspace/er-templates folder.
    • The name of the file must be included-section-handle.xsl
    • You need at least one template that matches entry
    • Protip: add ?debug to backend url to see the available xml for each entry.
    • Protip: You can also override the default debug template with
      <xsl:template match="/data" mode="debug" priority="1"></xsl:template>
    • Protip: You can create action buttons yourself, using the data-attribute api.
  • (Optional) Select a maximum recursion level for nested fields.
  • (Optional) Select a minimum and maximum number of elements for this field.
  • (Optional) Select an xsl mode to be able to support multiple templates for the same section.
  • (Optional) Select an xsl mode to customize the publish table view.
  • (Optional) Select an xsl mode to customize the publish action bar.
  • (Optional) Create some Reverse Relationship fields to be able to manage the relation in both sections!

There is also a screen cast available

Backend templates

Entries / publish view templates

Here's what a basic backend template should look like.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="entry">
    <div>
        <h1>
            <xsl:value-of select="./*[1]" />
        </h1>
    </div>
</xsl:template>

</xsl:stylesheet>

Field action bar template

Beware: this template must be in a xsl file named like the current section's handle (not the targeted sections)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="field" mode="[field settings mode]">
    <div>
        <xsl:if test="allow-new = 'yes'">
            <button type="button" class="create" data-create="[section-id]">Custom create new</button>
        </xsl:if>
    </div>
</xsl:template>

</xsl:stylesheet>

Default templates

Since version 2.0.0, the extension ships with default xsl templates that can be imported in your customized templates. Also, feel free to copy and change them as required for your current project.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="../../extensions/entry_relationship_field/er-templates/action-bar.xsl" />
<xsl:import href="../../extensions/entry_relationship_field/er-templates/entry.xsl" />

<xsl:template match="entry">
    <xsl:apply-templates select="." mode="content" />
</xsl:template>

<xsl:template match="entry" mode="[field settings mode for publish table view]">
    <xsl:apply-templates select="." mode="table-view" />
</xsl:template>

<xsl:template match="field" mode="[field settings mode for the action bar]">
    <xsl:apply-templates select="." mode="action-bar" />
</xsl:template>

</xsl:stylesheet>

Data-attribute API

In your backend template, you can create button that uses the same features as the default ones. The only markup needed is a data-attribute on the button.
The provided actions are:

  • Edit entry data-edit="{entry-id}"
  • Unlink entry data-unlink="{entry-id}"
  • Link entry data-link="{section-handle}"
  • Search entry data-search="{section-handle}"
  • Delete entry data-delete="{entry-id}"
  • Create entry data-create="{section-handle}"
  • Replace entry data-replace="{entry-id}"
  • Orderable handle selector data-orderable-handle=""
  • Collapsible selectors
    • Handle data-collapsible-handle=""
    • Content data-collapsible-content=""
  • Insert a specified index data-insert="" (only valid with data-create and data-link)
    • Leaving the data-insert attribute empty will make the insertion after the current entry.
    • Setting a number will insert after that index.
    • Setting -1 will insert before the current entry.

Attribute value is always optional: It will revert to the closest data-attribute it can find in the DOM.

If you are trying to act on unrelated sections, add the data-section="{section-handle}" attribute alongside the action one.

The search features uses Symphony's suggestion jQuery plug-in. In order for it to work in your template, use the following html.

<div data-interactive="data-interactive">
    <input data-search="" placeholder="Search for entries" autocomplete="off">
    <ul class="suggestions"></ul>
</div>

No validation is made to check if the feature has been activated in the field's settings. The template developer must properly check which setting is enabled in the field's xml.

AKNOWLEDGMENTS

This field would not have been created if some other people did not released some really cool stuff. We would like to thanks everybody that contributed to those projects:

We basically trashed things that were not necessary and re-implemented things that we liked from those extensions.

LICENSE

MIT

Made with love in Montréal by Deux Huit Huit

entry_relationship_field's People

Stargazers

 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

entry_relationship_field's Issues

Show the minimum and the maximum of entries

I thought it could be a good idea to show th number of entries there are in the field.

If there is no minimum or maximum count : "Showing 5 entries."
If there is a minimum count but no maximum : "Showing 1 entries. Needs at least 3."
If there is a maximum count but no minimum : "Showing 10 entries. Needs no more than 3."
If there is both a maximum and a minimum count : "Showing 10 entries. Needs at least 3. Needs no more than 20."

Or a simple "Min : 3 entries. Max 6 entries".

Cheers

Always show linking section

When there is only 1 section, the dropdown to select the section is not visible. It would be interesting to have a label with the name of the section we are linking with.

Deleting related entry causes error in primary entry

Testing this in a section called Projects and have an ERFfield attached linking to 3 sections: Images, Videos, Textareas.

Have associated the ERF with 3 images from the Images section.

If I delete an Image from the Images section and re-visit the Projects section, I get this error:

Symphony Warning: array_merge(): Argument #2 is not an array
An error occurred in /Applications/XAMPP/xamppfiles/htdocs/sym25/extensions/entry_relationship_field/fields/field.entry_relationship.php around line 824
819                 return __('None');
820             }
821             $entries = array_map(array('General', 'intval'), array_filter(array_map(trim, explode(self::SEPARATOR, $data['entries']))));
822             $realEntries = array();
823             foreach ($entries as $entryId) {
824                 $realEntries = array_merge($realEntries, EntryManager::fetch($entryId));
825             }
826             $count = count($entries);
827             $realCount = count($realEntries);
828             if ($count === $realCount) {

EDIT by @nitriques for block format

Markdown content not respected in the grouped output datasource

I've been trying to output markdown/html marked up data using the Entry Relationship DS, but nothing ever changes the output.. all I get is CDATA wrapped content with no tags surrounding strings of text that are split by new lines.. shouldn't they be outputting P tags etc??

Some basic backend result filter

Hi @nitriques I was thinking about when a lot of results are returned in the backend after clicking "Link to entry" button.

I'm not sure what's the best way to provide some sort of filtering but as you're loading the Publish page into the iframe already. Would it be good to not hide the "Filter Entries" button from the top and also in the section editor field have a box to input a custom filter to append to the url of the iframe src like.

?filter[title]=whatever

So people could choose to limit to certain entries being returned and also use the filter entries facility in general.

It seems to work ok when I hack your iframe src url. I can also return no entries this way until a suitable filter is applied.

Or maybe an option to hide the "Filter Entries" button if authors aren't allowed to alter the filters.

What do you think?

Datasource filtering not working

I'm trying to filter all comments for a particular article. Each comment uses a relationship field to associate it to a particular article. In the datasource I pass on the the url parameter that is the article id to the filter for the relationship field. The resulting datasource contains no entries though. When I use Select Box Link, or Association Field I get the expected comments. Is datasource filtering implemented in your extension yet?

Many thanks.

Illegal offset string error

Ok so I have associations using the Entry Relationship Field setup and linking to them is working fine.

But if I try and create a new association via the Associations Drawer and not the ERF UI I get this error:

Symphony Warning: Illegal string offset 'entries'
An error occurred in /Applications/XAMPP/xamppfiles/htdocs/sym26/extensions/entry_relationship_field/fields/field.entry_relationship.php around line 181
176          * @return Array - data to be inserted into DB
177          */
178         public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = null) {
179             $status = self::__OK__;
180             
181             $entries = $data['entries'];
182             
183             $row = array(
184                 'entries' => $entries
185             );

EDIT by @nitriques for block format

Selecting more than one relationship before save bug

I'm using the Dev branch with Symphony 2.6beta2 and experience a weird UI behaviour before saving the main section.

Main section is an article with an ERF linked to an images section.. I want to associate more than one image with the Article so choose 'link to entry' and associate one image as expected... then it returns to the main section no problem and the association is present in the UI. Now before saving, click 'link to entry' again and I attempt to associate another image.. this time it returns to the main section but the association does not appear in the UI... but if you save the main section, the association has actually saved.. it's just not appearing. there is an error in the JS of the extension from what I can see... in relation to https://github.com/DeuxHuitHuit/entry_relationship_field/blob/dev/assets/publish.entry_relationship_field.js#L293 ??

Could that be related maybe?

Textformatters and parenthisis tabs second tab no visible content

When linking an association to a new textarea section which has 2 tabs (1 for each language) the second tabs content is never instantiated.

Parenthisis tabs for the language switch
Textarea
Ckeditor textformatter

Going directly to the section is fine but linking or creating a new association via the ERF UI does not trigger the second tabs textarea content... could this be an iframe within an iframe issue maybe?

Can't create new content with a required entry relationship

If I have an Entry Relationship Field which is required on my section, I can't create new content in that section:

  • When I go to create the link I get an error along the lines of "Error while saving field X. Not enough parameters". I am also unable to save the entry after this even though the entry relationship field remains populated after the error pops up.
  • Equally, if I make the field non-required but then set "minimum count of entries in this field" to 1, I am able to save content without linking any entries in the field.

This is on Symphony 2.6.2. Any thoughts?

Bi-directional relationships

As discussed, I would like to propose that we modify the field to be able to see other Entry Relationship Fields in linked sections.

The scenario to work on is:

  • Three sections all link to each other using the Entry Relationship field; A, B, C.
  • An Entry in Section A creates a link to an Entry in Section B, and Section C.
  • An Entry in Section B creates a link to an Entry in Section A, and Section C.
  • An Entry in Section C creates a link to an Entry in Section A, and Section B.
  • When looking at an Entry in any Section, the Entry Relationship field displays a link to the Entries in the other Sections.

entry_relationships

How could we do this...? These are just some ideas...

  • We should have an option in the field settings (bi-directional) to allow the field to look for other fields that have the option selected.
  • We should use the sections_association table to look for these relationships.
  • I think that there maybe should be a single row for each relationship rather than a comma separated list in the field table.
  • When a relationship is created in a field with the bi-directional option, a partner relationship should be generated in the other fields table.

Correct me if I'm wrong though...

Add XSLT template for the header as well

Is there scope to effect the heading of each Entry Relationship block using the XSL templates at all?

With textareas it's starting to look very cluttered when editing an entry in a section.

Was just looking at how Craft deal with their Matrix field and it feels similar to ERF: http://buildwithcraft.com/docs/matrix-fields#the-field

Especially the bit about when an Entry Relation is open.. the content is inside, when it's collapsed we see a snippet of the content in the gray bar which is also knocked back to a gray colour text so as not to stand out/be too prominent.

Add a way to delete missing entries

As @andrewminton said in #19:

It also may be worth implementing an 'Unlink Entry' interface for redundant/missing entries?? When I re-visit the Entry containing ERF, I see a small notification indicating that Entry with ID number 3 in the Images section is missing... If I was able to remove that reference from within the entry as we can with currently available entries from the linked sections.. that would be great.

Output formatted markdown text

It would be useful to output formatted markdown both in the backend (available in the backend templates) and frontend (in the entry relationship field section data source).

Doesn't play at all with Association Field

When putting ERF into a section and using it to associate another section that has an Association Field in it. Then any attempt to access that section either through ERF or backend page causes this error.

Symphony Fatal Database Error: Unknown column 'd.entries' in 'where clause'

An error occurred while attempting to execute the following query

SELECT SQL_CACHE `e`.id, `e`.section_id, e.`author_id`, UNIX_TIMESTAMP(e.`creation_date`) AS `creation_date`, UNIX_TIMESTAMP(e.`modification_date`) AS `modification_date` FROM `ar6_entries` AS `e` INNER JOIN `ar6_entries_data_41` AS `d` ON `e`.id = `d`.`entry_id` WHERE 1 AND `e`.`section_id` = '10' AND (`d`.`entries` = '235' OR `d`.`entries` LIKE '235,%' OR `d`.`entries` LIKE '%,235' OR `d`.`entries` LIKE '%,235,%') ORDER BY ( SELECT `ed`.value FROM ar6_entries_data_12 AS `ed` WHERE entry_id = e.id ) ASC

Further I found that upon removing ERF the section is accessible but can no longer appear in the list of things to associate in the Association Field. Whatever links those tables together must be altered somehow I would guess.

Backup DB before trying the section stays broken.

Offer a data-attribute based API for the backend

This is related to #5 since this is how we would offer the feature (i.e. using data-attributes)

List of feature to implement

  • edit entry (data-edit="{entry-id}")
  • unlink entry (data-unlink="{entry-id}")
  • link entry (data-link="{section-handle}")
  • delete entry (data-delete="{entry-id}")
  • create entry (data-create="{section-handle")
  • replace entry (data-replace="{entry-id}")

numeric arguments are always optional

  • add doc in README

Import stylesheet error

Hey @nitriques can you help me find out about this problem? When I try to make a template like in your screencast it always says this error.

XSLTProcessor::importStylesheet(): compilation error: file file:///D:/wamp/www/munki-49/ line 3 element import

It doesn't say which file where the line 3 is. Even when my template is just like this I get the error

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
     <xsl:template match="entry"> 
     </xsl:template> 
</xsl:stylesheet>

My associated section is called "Photos", my template file is called photos.xsl

Cheers

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.