#2447277: Performance: replace sylesheets[all][] with attached changed the way that the date_api/date.css is added to the page. Instead of adding it everywhere globally, it uses #attached to add it selectively.

However, now the date_api/date.css file is not being added when a date select field is used on the page - in both Field API fields as well as custom Form API elements. This causes the date select fields to stack instead of displaying inline. See attached before/after screenshots.

Issue fork date-3067396

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

m.stenta created an issue. See original summary.

m.stenta’s picture

I tried figuring out how to get the CSS file properly added to form elements with #attached but ran out of time, alas.

Attached is a patch that simply reverts the change from #2447277: Performance: replace sylesheets[all][] with attached. I am not suggesting we revert the change, but I will need to use this patch with my Drush make file in the meantime to fix it for my sites.

m.stenta’s picture

Issue summary: View changes
m.stenta’s picture

Status: Active » Needs review
FileSize
593 bytes

Ok, here is a simple one-line patch. Because my first patch didn't actually apply perfectly to the 7.x-2.11-beta2 release (this one does) - and it can be a first step to kick off the process. It works, but it might not be the right way to do it.

Make it work then make it good.

leendertdb’s picture

I can confirm this issue with the current 7.x-2.x-dev version. It breaks the node edit display (being used in our front-end theme) compared to the current release version, because the date_api/date.css file is no longer included.

I decided to simply append the date.css in our theme's stylesheet for the time being, so haven't tested the patch yet. Just wanted to chip in that more people are experiencing this issue and that this bug can break CSS for existing sites.

ciss’s picture

Please note that the issue applies to other element types as well. We've noticed this with the Scheduler module which uses a date_popup element.

DamienMcKenna’s picture

Title: Date CSS not added for date_select Form API elements » Date CSS not added for all Form API elements
Priority: Normal » Major
Status: Needs review » Needs work
Issue tags: +Regression

Thanks for working on this.

I wonder if we should list date.css as a library using hook_library() and then list it as a dependency in date_popup_library(), and just use e.g. drupal_add_library('date_api', 'date'); when needed?

steinmb’s picture

Status: Needs work » Needs review
FileSize
981 bytes

Do you mean something like this? Testing in a view where I had a exposed date filter using date_popup. With this it load date.css

DamienMcKenna’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Yes, that sort of thing, though it needs the long array syntax so it can be compatible with PHP 5.3. Yeah, I know ;-)

steinmb’s picture

Sorry, I missed your feedback on this issue. Here is a "good" old PHP 5.3.x complaint patch. Did not realise date needed to support that that old versions but it sort of make sense.

Tests you say. I could try, but I have to bother you for some more information if you find the time. Where and what do you suggest we should write tests for? Example, test that the library is defined by date_api ?

public function testLibrary() {
  $date_api_path = drupal_get_path('module', 'date_api');
  $date_api_library = drupal_get_library('date_api', 'date_api');

 $this->assertEqual($date_api_library['title'], 'Date module main library', 'Date library found');
 $this->assertEqual($date_api_library["css"][0], $date_api_path . '/date.css', 'Date API CSS found');

Or/and try to test if the date.css is loaded and included edit/creation of node:

$this->drupalGet('node/add/story');
$this->assertResponse(200);
$this->assertRaw('date/date.css');

No export in writing tests for old D7...

steinmb’s picture

Status: Needs work » Needs review
.bert’s picture

I like that idea of adding it as a library dependency.

But this patch only applies to date_popup field types though. What's the best way to capture this method for the other field types such as date_select?

DamienMcKenna’s picture

Status: Needs review » Needs work

Let's expand this to cover all scenarios where date.css is loaded.

And for the test coverage, the second method to check the output for date/date.css would be fine.

kunal_sahu made their first commit to this issue’s fork.

kunal_sahu’s picture

I am writing some testcases . Please review my MR. Thanks

raywright’s picture

Just curious if anyone was successful in applying the date.css to select fields? I have applied the patch as it stands but my select date select fields (month, day, year) still stack on top of each other rather than float as the CSS styles them.