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 :)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett’s picture

Status: Active » Needs review
FileSize
44.45 KB
4.03 KB
3.26 KB

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:

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
FileSize
4.4 KB
13 KB
2.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
FileSize
5.31 KB
4.12 KB

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

tim.plunkett’s picture

FileSize
17.05 KB

@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
FileSize
17.11 KB

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
FileSize
576 bytes
635 bytes

Good idea!

dawehner’s picture

Version: 8.x-3.x-dev » 7.x-3.x-dev
FileSize
576 bytes

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

tim.plunkett’s picture

FileSize
576 bytes

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.