Commit bd58fd46 authored by johnv's avatar johnv

Issue #2898234: Apply coding standards

parent 065cda81
......@@ -36,7 +36,7 @@
});
// Copy values from previous day, when user clicks "Copy previous day".
// @todo: works for Table widget, not yet for List Widget.
// @todo This works for Table widget, not yet for List Widget.
$('.office-hours-copy-link').bind('click', function (e) {
e.preventDefault();
......
......@@ -67,7 +67,7 @@ function template_preprocess_office_hours(&$variables) {
$items = [];
// Schema part.
// @todo: move to ..._preprocess_office_hours_schema, or use RDF module's twig.
// @todo Move to ..._preprocess_office_hours_schema, or use RDF module's twig.
if (isset($office_hours['schema'])) {
$schema_items = [];
foreach ($office_hours['schema'] as $schema) {
......@@ -89,7 +89,7 @@ function template_preprocess_office_hours(&$variables) {
'slots' => ['#type' => 'markup', '#markup' => $info['formatted_slots']],
'comments' => ['#type' => 'markup', '#markup' => $info['comments']],
'suffix' => $variables['item_separator'],
// @todo: use $variables['item_separator'] in office-hours.html.twig.
// @todo Use $variables['item_separator'] in office-hours.html.twig.
];
}
......
......@@ -3,7 +3,9 @@
/**
* @file
* Provide Views data and handlers for office_hours.module.
* @TODO: finish upgrade to D8, see advanced help: http://www.example.com/help/views/api-upgrading
*
* @todo Finish upgrade to D8.
* @see Advanced help: http://www.example.com/help/views/api-upgrading
*
* @ingroup views_module_handlers
*/
......@@ -95,7 +97,7 @@ function _office_hours_views_field_views_data(\Drupal\field\FieldStorageConfigIn
case 'text':
case 'blob':
// TODO add markup handlers for these types
// @todo Add markup handlers for these types.
default:
$filters[] = 'content_handler_filter_string';
$arguments[] = 'content_handler_argument_string';
......@@ -128,8 +130,8 @@ function _office_hours_views_field_views_data(\Drupal\field\FieldStorageConfigIn
'field' => $column,
'table' => $db_info['table'],
'handler' => $arguments[$i],
'click sortable' => $sorts[$i], // TODO used in once place in node.views.inc, should we use it here?
'name field' => '', // TODO
'click sortable' => $sorts[$i], // @todo used in once place in node.views.inc, should we use it here?
'name field' => '', // @todo
//'additional fields' => $additional_fields,
'content_field_name' => $field_storage['field_name'],
'empty field name' => t('<No value>'),
......@@ -148,7 +150,7 @@ function _office_hours_views_field_views_data(\Drupal\field\FieldStorageConfigIn
$i++;
}
// TODO do we need different handling for sorts with Views 2,
// @todo Do we need different handling for sorts with Views 2,
// especially when relationships are involved?
if (!empty($sorts[$i])) {
$data[$column]['sort'] = [
......@@ -160,7 +162,7 @@ function _office_hours_views_field_views_data(\Drupal\field\FieldStorageConfigIn
'allow empty' => TRUE,
];
}
// @todo: provide automatic filters, sorts, and arguments
// @todo Provide automatic filters, sorts, and arguments.
// for each column, not just the first?
return [$table_alias => $data];
}
......
......@@ -88,10 +88,10 @@ class OfficeHoursDatetime extends Datetime {
public static function processOfficeHours(&$element, FormStateInterface $form_state, &$complete_form) {
$element = parent::processDatetime($element, $form_state, $complete_form);
// @todo: use $element['#date_time_callbacks'], do not use this function.
// @todo Use $element['#date_time_callbacks'], do not use this function.
// Adds the HTML5 attributes.
$element['time']['#attributes'] = [
// @todo: set a proper from/to title.
// @todo Set a proper from/to title.
// 'title' => $this->t('Time (e.g. @format)', ['@format' => static::formatExample($time_format)]),
// Fix the convention: minutes vs. seconds.
'step' => $element['#date_increment'] * 60,
......@@ -110,7 +110,7 @@ class OfficeHoursDatetime extends Datetime {
public static function validateOfficeHours(&$element, FormStateInterface $form_state, &$complete_form) {
$input_exists = FALSE;
// @todo: call validateDatetime().
// @todo Call validateDatetime().
// Get the 'time' sub-array.
$input = NestedArray::getValue($form_state->getValues(), $element['#parents'], $input_exists);
// Generate the 'object' sub-array.
......@@ -127,7 +127,7 @@ class OfficeHoursDatetime extends Datetime {
*/
/**
* @todo: use Core/TypedData/ComplexDataInterface
* @todo Use Core/TypedData/ComplexDataInterface.
* There are too many similar functions:
* - OfficeHoursWidgetBase::massageFormValues();
* - OfficeHoursItem, which requires an object;
......
......@@ -52,8 +52,8 @@ class OfficeHoursList extends FormElement {
* @return
*/
public static function processOfficeHoursSlot(&$element, FormStateInterface $form_state, &$complete_form) {
// @todo D8: $form_state = ...
// @todo D8: $form = ...
// @todo D8 $form_state = ...
// @todo D8 $form = ...
$slot_class = 'office-hours-slot';
$element['#attributes']['class'][] = 'form-item'; //D8
......
......@@ -26,8 +26,8 @@ class OfficeHoursSlot extends OfficeHoursList {
public static function processOfficeHoursSlot(&$element, FormStateInterface $form_state, &$complete_form) {
// Fill with default data from a List element.
$element = parent::processOfficeHoursSlot($element, $form_state, $complete_form);
// @todo D8: $form_state = ...
// @todo D8: $form = ...
// @todo D8 $form_state = ...
// @todo D8 $form = ...
$max_delta = $element['#field_settings']['cardinality_per_day'] - 1;
$day_delta = $element['#daydelta'];
......
......@@ -222,7 +222,7 @@ class OfficeHoursDateHelper extends DateHelper {
break;
case 'two_letter':
// @todo: avoid translation from English to XX, in case of 'Microdata'.
// @todo Avoid translation from English to XX, in case of 'Microdata'.
return self::weekDaysAbbr2(TRUE);
break;
......
......@@ -371,12 +371,14 @@ abstract class OfficeHoursFormatterBase extends FormatterBase {
return Cache::PERMANENT;
case 'current':
// dpm($items, __CLASS__.'/'.__FUNCTION__.'/'.__LINE__);
// Cache expires at midnight.
$next_time = '0000';
$add_days = 1;
break;
case 'next':
// dpm($items, __CLASS__.'/'.__FUNCTION__.'/'.__LINE__);
/** @var OfficeHoursItemListInterface $items */
$office_hours = $items->getRows($settings, $this->getFieldSettings());
......
......@@ -40,6 +40,9 @@ class OfficeHoursFormatterTable extends OfficeHoursFormatterBase {
return $elements;
}
$office_hours = $items->getRows($this->getSettings(), $this->getFieldSettings());
// For a11y screen readers, a header is introduced.
// Superfluous comments are removed. @see #3110755 for examples and explanation.
$isCommentEnabled = $this->fieldDefinition->getFieldStorageDefinition()->getSetting('comment');
// Build the Table part.
$table_rows = [];
......@@ -49,22 +52,26 @@ class OfficeHoursFormatterTable extends OfficeHoursFormatterBase {
'label' => [
'data' => ['#markup' => $item['label']],
'class' => ['office-hours__item-label', ],
'header' => !$isCommentEnabled,
],
'slots' => [
'data' => ['#markup' => $item['formatted_slots'] ],
'class' => ['office-hours__item-slots', ],
],
'comments' => [
'data' => ['#markup' => $item['comments'] ],
'class' => ['office-hours__item-comments', ],
],
],
'no_striping' => TRUE, // @todo: Does not work. Why? Solved in css.
'no_striping' => TRUE, // @todo Does not work. Why? Solved in css.
'class' => ['office-hours__item', ],
];
}
// @todo #2720335 : try to get the meta data into the <tr>.
if ($isCommentEnabled) {
$table_rows[$delta]['data']['comments'] = [
'data' => ['#markup' => $item['comments']],
'class' => ['office-hours__item-comments'],
];
}
}
// @todo #2720335 Try to get the meta data into the <tr>.
// foreach ($table_rows as $delta => &$row) {
// $row['#metadata']['itemprop'] = "openingHours";
// $row['#metadata']['property'] = "openingHours";
......@@ -85,6 +92,23 @@ class OfficeHoursFormatterTable extends OfficeHoursFormatterBase {
],
];
if ($isCommentEnabled) {
$table['#header'] = [
[
'data' => $this->t('Day'),
'class' => 'visually-hidden',
],
[
'data' => $this->t('Time slot'),
'class' => 'visually-hidden',
],
[
'data' => $this->t('Comment'),
'class' => 'visually-hidden',
],
];
}
$elements[] = [
'#theme' => 'office_hours_table',
'#table' => $table,
......
......@@ -121,7 +121,7 @@ class OfficeHoursItem extends FieldItemBase {
$element['cardinality_per_day'] = [
'#type' => 'select',
'#title' => $this->t('Number of time slots per day'),
// @todo for 'multiple slots per day': add support for FIELD_CARDINALITY_UNLIMITED.
// @todo For 'multiple slots per day': add support for FIELD_CARDINALITY_UNLIMITED.
// '#options' => [FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED => $this->t('unlimited')) + drupal_map_assoc(range(1, 10)],
'#options' => array_combine(range(1, 12), range(1, 12)),
'#default_value' => $settings['cardinality_per_day'],
......@@ -129,7 +129,7 @@ class OfficeHoursItem extends FieldItemBase {
// '#disabled' => $has_data,
];
// @todo D8: align with DateTimeDatelistWidget.
// @todo D8 Align with DateTimeDatelistWidget.
$element['time_format'] = [
'#type' => 'select',
'#title' => $this->t('Time notation'),
......@@ -153,7 +153,7 @@ class OfficeHoursItem extends FieldItemBase {
],
'#default_value' => $this->getSetting('element_type'),
];
// @todo D8: align with DateTimeDatelistWidget.
// @todo D8 Align with DateTimeDatelistWidget.
$element['increment'] = [
'#type' => 'select',
'#title' => $this->t('Time increments'),
......@@ -223,7 +223,7 @@ class OfficeHoursItem extends FieldItemBase {
*/
public function getConstraints() {
$constraints = [];
// @todo: when adding parent::getConstraints(), only English is allowed...
// @todo When adding parent::getConstraints(), only English is allowed...
// $constraints = parent::getConstraints();
$max_length = $this->getSetting('max_length');
if ($max_length) {
......
......@@ -35,9 +35,9 @@ class OfficeHoursDefaultWidget extends OfficeHoursWidgetBase {
protected function formMultipleElements(FieldItemListInterface $items, array &$form, FormStateInterface $form_state) {
$field_cardinality = $this->fieldDefinition->getFieldStorageDefinition()
->getCardinality();
if ($field_cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {
if ($field_cardinality == FieldStorageDefinitionInterface ::CARDINALITY_UNLIMITED) {
$this->fieldDefinition->getFieldStorageDefinition()
->setCardinality(7 * $this->getFieldSetting('cardinality_per_day'));
->setCardinality(7 * $this->getFieldSetting('cardinality_per_day')); // @todo D9 test
}
$elements = parent::formMultipleElements($items, $form, $form_state);
......@@ -80,7 +80,7 @@ class OfficeHoursDefaultWidget extends OfficeHoursWidgetBase {
$cardinality = $this->getFieldSetting('cardinality_per_day');
$id = -1;
foreach ($days as $index => $day) {
// todo: theme_function clears values above cardinality. move it here.
// @todo The theme_function clears values above cardinality. Move it here.
for ($daydelta = 0; $daydelta < $cardinality; $daydelta++) {
$id++;
$elements[$id]['#day'] = $day;
......@@ -88,7 +88,7 @@ class OfficeHoursDefaultWidget extends OfficeHoursWidgetBase {
$elements[$id]['#dayname'] = $daynames[$day];
$elements[$id]['#type'] = 'office_hours_slot';
$elements[$id]['#default_value'] = isset($indexed_items[$day][$daydelta]) ? $indexed_items[$day][$daydelta]->getValue() : NULL;
$elements[$id]['#default_value'] = isset($indexed_items[$day][$daydelta]) ? $indexed_items[$day][$daydelta]->getValue() : NULL; // @todo D9 test
$elements[$id]['#field_settings'] = $element['#field_settings'];
$elements[$id]['#date_element_type'] = $this->getSetting('date_element_type');
}
......
......@@ -6,8 +6,6 @@ use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\office_hours\Element\OfficeHoursDatetime;
use Drupal\office_hours\Element\OfficeHoursSlot;
use Drupal\office_hours\OfficeHoursDateHelper;
/**
* Base class for the 'office_hours_*' widgets.
......@@ -23,7 +21,8 @@ abstract class OfficeHoursWidgetBase extends WidgetBase {
foreach ($values as $key => &$item) {
// Note: below could better be done in OfficeHoursItemList::filter().
// However, then we have below error "value '' is not allowed".
// @todo: check above again, now Issue 3065358-7 is solved.
// @todo Check above again, now Issue 3065358-7 is solved.
// @todo This is only for HTML5, not for SelectList hours.
if (empty($item['comment'])) {
if (OfficeHoursDatetime::isEmpty($item['starthours'])
&& OfficeHoursDatetime::isEmpty($item['endhours'])
......@@ -37,7 +36,7 @@ abstract class OfficeHoursWidgetBase extends WidgetBase {
if (OfficeHoursDatetime::isEmpty($item['starthours'])
|| OfficeHoursDatetime::isEmpty($item['endhours'])
) {
// @todo : move to validate function.
// @todo Move to validate function.
$field_name = $this->fieldDefinition->getName();
$form_state->setErrorByName("$field_name][value][$key", t('Slot has a comment, but those times not filled.'));
continue;
......@@ -51,7 +50,8 @@ abstract class OfficeHoursWidgetBase extends WidgetBase {
// "This value should be of the correct primitive type."
// This is needed for e.g., 0000 and 0030.
$item['starthours'] = isset($start) ? (int) $start : '';
$item['endhours'] = isset($end) ? (int) $end : '';
$item['endhours'] = isset($end) ? (int) $end : NULL;
$item['endhours'] = !empty($end) ? (int) $end : NULL;
// #2070145: Allow Empty time field with comment.
// In principle, this prohibited by the database: value '' is not
// allowed. The format is int(11).
......
......@@ -73,17 +73,18 @@ class OfficeHoursFieldTest extends FieldKernelTestBase {
]);
$this->field->save();
/** @var @ $entity_display */
$entity_display = EntityViewDisplay::create([
'targetEntityType' => $this->field->getTargetEntityTypeId(),
'bundle' => $this->field->getTargetBundle(),
'mode' => 'default',
]);
// Save the office hours field as the table formatter to check if the
// config schema is valid.
// Save the office hours field to check if the config schema is valid.
// @todo D9 test
// Table formatter.
$entity_display->setComponent('field_office_hours', ['type' => 'office_hours_table']);
$entity_display->save();
// Save the office hours field as the default formatter to check if the
// config schema is valid.
// Default formatter.
$entity_display->setComponent('field_office_hours', ['type' => 'office_hours']);
$entity_display->save();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment