In FullCalendar, there is a need to select on of the added fields as "THE DATE FIELD". Similarly, you can specify one as the Title and the URL to override the entity title and URL.

I've reused this mechanism on several client sites, and I'm tired of doing that without abstracting it :)

Files: 
CommentFileSizeAuthor
#20 views-1765824-20.patch576 bytestim.plunkett
PASSED: [[SimpleTest]]: [MySQL] 1,598 pass(es).
[ View ]
#19 views-1765824-18-D7-do-not-test.patch576 bytesdawehner
#18 views-1765824-18-D8.patch635 bytestim.plunkett
PASSED: [[SimpleTest]]: [MySQL] 1,708 pass(es).
[ View ]
#18 views-1765824-18-D7-do-not-test.patch576 bytestim.plunkett
#16 views-1765824-16.patch17.11 KBtim.plunkett
PASSED: [[SimpleTest]]: [MySQL] 1,598 pass(es).
[ View ]
#7 views-1765824-7.patch17.05 KBtim.plunkett
PASSED: [[SimpleTest]]: [MySQL] 1,693 pass(es).
[ View ]
#6 views-1765824-6.patch4.12 KBtim.plunkett
PASSED: [[SimpleTest]]: [MySQL] 1,631 pass(es).
[ View ]
#6 interdiff.txt5.31 KBtim.plunkett
#4 views-fullcalendar-1765824-4-do-not-test.patch2.56 KBtim.plunkett
#4 views-1765824-4-D7.patch13 KBtim.plunkett
PASSED: [[SimpleTest]]: [MySQL] 1,555 pass(es).
[ View ]
#4 interdiff.txt4.4 KBtim.plunkett
#1 views-1765824-1-d8.patch3.26 KBtim.plunkett
PASSED: [[SimpleTest]]: [MySQL] 1,631 pass(es).
[ View ]
#1 views-1765824-1-d7-do-not-test.patch4.03 KBtim.plunkett
#1 views-1765824-1-screenshot.png44.45 KBtim.plunkett

Comments

tim.plunkett’s picture

Status:Active» Needs review
StatusFileSize
new44.45 KB
new4.03 KB
new3.26 KB
PASSED: [[SimpleTest]]: [MySQL] 1,631 pass(es).
[ View ]

Since this would require extremely custom theming in the style plugin, it's declared as a 'no ui' and needs to be extended. Here's a screenshot of 4 fields, the first of which has a description and is optional.

views-1765824-1-screenshot.png

tim.plunkett’s picture

Here's the example class (D7) used to generate the screenshot:

<?php
class example_thing extends views_plugin_style_mapping {

 
/**
   * Overrides views_plugin_style_mapping::define_mapping().
   */
 
function define_mapping() {
    return array(
     
'title' => array(
       
'label' => t('Title'),
       
'default' => 'title',
       
'optional' => TRUE,
       
'description' => t('This is the title field'),
      ),
     
'text' => array(
       
'label' => t('Text'),
      ),
     
'image' => array(
       
'label' => t('Image'),
      ),
     
'link' => array(
       
'label' => t('Link'),
      ),
    );
  }

}
?>
aspilicious’s picture

Don't we need ta mechanism to add some kind of filtering on the fields?
For example I know we only use real date fields in fullcalendar when we search for a date field.

tim.plunkett’s picture

Version:8.x-3.x-dev» 7.x-3.x-dev
Issue tags:+needs backport to D7
StatusFileSize
new4.4 KB
new13 KB
PASSED: [[SimpleTest]]: [MySQL] 1,555 pass(es).
[ View ]
new2.56 KB

Rolling a D7 patch for now as a proof of concept to show how it could work with fullcalendar.
If it makes sense I can forward port it.

dawehner’s picture

Status:Needs review» Needs work

Yeah i have seen a lot of similar plugins, like many slideshow/image related ones, so i would vote to introduce such a feature.

+++ b/lib/Drupal/views/Plugin/views/style/Mapping.phpundefined
@@ -0,0 +1,108 @@
+class Mapping extends StylePluginBase {

Can you explain how to use that without an actual subclass? So it seems to make sense to remove the @Plugin() and make the class abstract

+++ b/lib/Drupal/views/Plugin/views/style/Mapping.phpundefined
@@ -0,0 +1,108 @@
+      if ($optional = !empty($mapping[$key]['optional'])) {
+        $field_options = array('' => t('- None -'));

It seems to be that you want to have the default as optional, so what about using a 'required' here instead?

+++ b/lib/Drupal/views/Plugin/views/style/Mapping.phpundefined
@@ -0,0 +1,108 @@
+      $form['views_field_mappings'][$key] = array(

What about removing the views_ prefix here, this seems kind of redundant.

tim.plunkett’s picture

Version:7.x-3.x-dev» 8.x-3.x-dev
Status:Needs work» Needs review
StatusFileSize
new5.31 KB
new4.12 KB
PASSED: [[SimpleTest]]: [MySQL] 1,631 pass(es).
[ View ]

Okay, I forward ported this, and took into account #5.
Here's an interdiff against #1.

tim.plunkett’s picture

StatusFileSize
new17.05 KB
PASSED: [[SimpleTest]]: [MySQL] 1,693 pass(es).
[ View ]

@aspilicious asked for tests, which I wrote, but I did it on top of #1771944: Replace exported views in tests with config files

So this will break for now, but a retest as soon as that's committed should pass.

Status:Needs review» Needs work
Issue tags:-needs backport to D7

The last submitted patch, views-1765824-7.patch, failed testing.

tim.plunkett’s picture

Status:Needs work» Needs review
Issue tags:+needs backport to D7

#7: views-1765824-7.patch queued for re-testing.

aspilicious’s picture

Looks good but the indentation for yaml file changed. 2 spaces it is now :)

dawehner’s picture

Status:Needs review» Reviewed & tested by the community

The 2 spaces aren't really a big issue, but yeah it should be better corrected but hey if you don't want to do it, this is a good novice issue.

+++ b/lib/Drupal/views/Tests/Plugin/StyleTestBase.phpundefined
@@ -0,0 +1,43 @@
+   * Stores a view output in the elements.
+   */
+  function storeViewPreview($output) {

Let's clean up things like that later.

+++ b/lib/Drupal/views/Tests/Plugin/StyleUnformattedTest.phpundefined
@@ -29,25 +20,6 @@ public static function getInfo() {
-  protected function setUp() {
-    parent::setUp();
-
-    $this->enableViewsTestModule();
-  }
-
-  /**
-   * Stores a view output in the elements.
-   */
-  function storeViewPreview($output) {
-    $htmlDom = new DOMDocument();
-    @$htmlDom->loadHTML($output);
-    if ($htmlDom) {
-      // It's much easier to work with simplexml than DOM, luckily enough
-      // we can just simply import our DOM tree.
-      $this->elements = simplexml_import_dom($htmlDom);
-    }

Good redunction of the code.

+++ b/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/style/MappingTest.phpundefined
@@ -0,0 +1,70 @@
+  protected function allowNumericFields(&$fields) {

Maybe filterNumericFields could be better name

tim.plunkett’s picture

Assigned:Unassigned» tim.plunkett

Funny, I had filterNumericFields the first time. I'll change that before committing.
The spaces can be fixed in #1774290: Change YAML file indentations to 2 spaces

tim.plunkett’s picture

Version:8.x-3.x-dev» 7.x-3.x-dev
Status:Reviewed & tested by the community» Patch (to be ported)
tim.plunkett’s picture

Status:Patch (to be ported)» Needs review
StatusFileSize
new17.11 KB
PASSED: [[SimpleTest]]: [MySQL] 1,598 pass(es).
[ View ]

Wow, D7 is already soooo painful to use

dawehner’s picture

Version:7.x-3.x-dev» 8.x-3.x-dev
Status:Needs review» Active
+++ b/plugins/views_plugin_style_mapping.incundefined
@@ -0,0 +1,127 @@
+  protected function define_mapping() {

I'm wondering whether it would make sense to mark this as abstract so it is required to implement.

Committed to 7.x-3.x

tim.plunkett’s picture

Assigned:tim.plunkett» Unassigned
Status:Active» Needs review
StatusFileSize
new576 bytes
new635 bytes
PASSED: [[SimpleTest]]: [MySQL] 1,708 pass(es).
[ View ]

Good idea!

dawehner’s picture

Version:8.x-3.x-dev» 7.x-3.x-dev
StatusFileSize
new576 bytes

Perfect! Let's see what the tests tells us on d7.

tim.plunkett’s picture

StatusFileSize
new576 bytes
PASSED: [[SimpleTest]]: [MySQL] 1,598 pass(es).
[ View ]

Without the "do-not-patch"

dawehner’s picture

Status:Needs review» Fixed

hehe, it's green and go!

Automatically closed -- issue fixed for 2 weeks with no activity.