- Issue created by @Ahmed.Raza
- 🇳🇱Netherlands johnv
Please tell me which formatter you select.
There is a 'default' formatter, which just outputs text.
There is a 'table' formatter, that outputs a ... table.
That comes close to your request.
Or, perhaps, you want a Views record for each day, as if the field is a multi-value field. - 🇵🇰Pakistan Ahmed.Raza
Hi @johnv, we need the ability to show days like this on a Views table. Basically each day of the week showing its hours in individual column.
- 🇳🇱Netherlands johnv
Hi, I am not very good in theming.
The formatters that are provided show all data as a list, not as a row.i think you can use either one of the following methods:
- provide a new formatter
- use the 'default' formatter, and set the 'separators' in the formatter settings, to create/mimic the columns.
- use a preprocess hook from office_hours.theme.inc . Here you have the formatted 'office_hours', and also the original 'itemList'to work with
- change a twig template, the are in the 'templates' directoryI am keen on hearing your result.
- 🇵🇰Pakistan Ahmed.Raza
Hi Johnv, I ended up writing my own Views field plugin and rendering the hours information for each day of the week in its own column. But it'd be great to have separate fields in the Views and this is something doable, an example is the popular Address → field module. This is a should have in case you want to export the data into a CSV for example Google Business that was the case for us we had to export the data into a specific format which required us to have these opening and closing hours information of each day of the week into its own column within the CSV. We were using views_data_export to generate the CSV but had no way to showing hours of each day into their separate columns.
My custom solution:
Address module fields:
- 🇳🇱Netherlands johnv
In the past I did updte Google Places with views_data_export.
For that, i used the Default Text formatter, notthe Table formatter.
Then, you can set the delimiter to ; or , and export the data.
I will check your code nonetheless. - 🇨🇦Canada bisonbleu
@Ahmed.Raza Your solution is also what I'm looking for, do you mind sharing your code ?
- 🇳🇱Netherlands johnv
You may try the following:
- create a view;
- under Fields, add fields Title, ID, Office_hours
- under Format/Format, set to 'Unformatted list' of 'Fields'
- under Format/Show, set to 'Fields', with an 'Unformatted list' of 'Fields'
- Under Format/Show, set all fields to 'Inline', adding ';' as a separator;
- under Fields, set Office_hours formatter to 'default', which is a plain text formatter. Set the days formatter to ';', removing the default line break. Set other formatting options.This should give the required result for a csv export. Views_data_export can be used to generate a file in batch mode.
- For Office_hours, set the default formatter. This is/should be plain text.
- 🇳🇱Netherlands johnv
Above instructions were updated.
The following issue fixes a problem with white spaces in the output: 🐛 Remove white space in plain text formatter Fixed
- 🇳🇱Netherlands johnv
Other options:
Search how to swap table rows and columns in drupal views
This unveals an (outdated?) Views Template plugin: https://drupal.stackexchange.com/questions/222231/views-table-output-cha... - 🇵🇰Pakistan Ahmed.Raza
Hi guys here are the files from custom solution in case someone is looking the same thing.
Place "OfficeHours.php" inside 'src/Plugin/views/field/' of your custom mdoule and "mymodule.views.inc" inside your custom modules' root folder. Make the appropriate changes as per your needs clear the caches and you should be good to go.
Thanks
- Status changed to Fixed
10 months ago 9:43am 26 January 2024 - 🇳🇱Netherlands johnv
@ahmed.azra, thanks a lot for your code.
I gave me a good starting point. The end code doesn't look like it at all, though.Please check latest dev version, or upcoming vesion 8.x-1.13
Feedback is appreciated.
Automatically closed - issue fixed for 2 weeks with no activity.