Commit cdbca0cd authored by John Voskuilen's avatar John Voskuilen
Browse files

Issue #3219111: Clean code - phpcs

parent 78dfea46
Loading
Loading
Loading
Loading
+50 −48
Original line number Diff line number Diff line
@@ -13,11 +13,11 @@ use Drupal\office_hours\OfficeHoursDateHelper;
 * hook_field_formatter_settings_summary_alter
 * 	 Alters the field formatter settings summary.
 * hook_field_formatter_third_party_settings_form
 * 	 Allow modules to add settings to field formatters provided by other modules.
 * 	 Allow modules to add field formatter settings, provided by other modules.
 * hook_field_widget_settings_summary_alter
 *   Alters the field widget settings summary.
 * hook_field_widget_third_party_settings_form
 *   Allow modules to add settings to field widgets provided by other modules.
 *   Allow modules to add field widget settings, provided by other modules.
 */

/**
@@ -51,17 +51,19 @@ function office_hours_exceptions_preprocess_field(array &$variables) {

  // If field settings for this view_mode are not set, yet.
  if (!isset($settings['exceptions']['title'])) {
    \Drupal::messenger()->addMessage(
      t("Please review the display settings
    \Drupal::messenger()->addMessage(t("Please review the display settings
      for field %field_name in view mode %view_mode, and save them again.", [
        '%field_name' => $field_name,
        '%view_mode' => $view_mode]));
        '%view_mode' => $view_mode,
      ]
    ));
    return $elements;
  }

  // Loop over formatters: $elements contains table/status/schema formatter.
  $label = $settings['exceptions']['title'] ?? '';
  foreach ($elements as $key => &$element) if (is_numeric($key)) {
  foreach ($elements as $key => &$element) {
    if (is_numeric($key)) {
      // If there is an exception, add an extra row to label the exceptions.
      // Note: may be changed in template_preprocess_office_hours_table().
      $exception_header = [];
@@ -106,7 +108,7 @@ function office_hours_exceptions_preprocess_field(array &$variables) {
        // Sort, to ensure that the header is before the exceptions.
        $formatter_rows = OfficeHoursDateHelper::weekDaysOrdered($formatter_rows, $settings['office_hours_first_day']);
      }

    }
  }

  return $elements;
+3 −1
Original line number Diff line number Diff line
@@ -404,8 +404,10 @@ abstract class OfficeHoursFormatterBase extends FormatterBase {
  /**
   * Add a ['#cache']['max-age'] attribute to $elements, if necessary.
   *
   * @param OfficeHoursItemListInterface $items
   * @param \Drupal\office_hours\Plugin\Field\FieldType\OfficeHoursItemListInterface $items
   *   The office hours.
   * @param array $elements
   *   The list of formatters.
   */
  protected function addCacheMaxAge(OfficeHoursItemListInterface $items, array &$elements) {
    $field_definition = $items->getFieldDefinition();
+2 −1
Original line number Diff line number Diff line
@@ -41,7 +41,8 @@ class OfficeHoursFormatterDefault extends OfficeHoursFormatterBase {
    $settings = $this->getSettings();
    $third_party_settings = $this->getThirdPartySettings();
    $field_definition = $items->getFieldDefinition();
    // N.B. 'Show current day' may return nothing in getRows(), while other days are filled.
    // N.B. 'Show current day' may return nothing in getRows(),
    // while other days are filled.
    /** @var \Drupal\office_hours\Plugin\Field\FieldType\OfficeHoursItemListInterface $items */
    $office_hours = $items->getRows($settings, $this->getFieldSettings(), $third_party_settings);

+2 −1
Original line number Diff line number Diff line
@@ -75,7 +75,8 @@ class OfficeHoursFormatterSchema extends OfficeHoursFormatterBase {
    // Get some settings from field. Do not overwrite defaults.
    $settings = $this->defaultSettings() + $this->getSettings();
    $third_party_settings = $this->getThirdPartySettings();
    // N.B. 'Show current day' may return nothing in getRows(), while other days are filled.
    // N.B. 'Show current day' may return nothing in getRows(),
    // while other days are filled.
    /** @var \Drupal\office_hours\Plugin\Field\FieldType\OfficeHoursItemListInterface $items */
    $office_hours = $items->getRows($settings, $this->getFieldSettings(), $third_party_settings);
    $elements[] = [
+3 −2
Original line number Diff line number Diff line
@@ -41,7 +41,8 @@ class OfficeHoursFormatterTable extends OfficeHoursFormatterBase {
    $settings = $this->getSettings();
    $third_party_settings = $this->getThirdPartySettings();
    $field_definition = $items->getFieldDefinition();
    // N.B. 'Show current day' may return nothing in getRows(), while other days are filled.
    // N.B. 'Show current day' may return nothing in getRows(),
    // while other days are filled.
    /** @var \Drupal\office_hours\Plugin\Field\FieldType\OfficeHoursItemListInterface $items */
    $office_hours = $items->getRows($settings, $this->getFieldSettings(), $third_party_settings);

@@ -51,7 +52,7 @@ class OfficeHoursFormatterTable extends OfficeHoursFormatterBase {
    }

    // For accessibility (a11y) screen readers, a header/title is introduced.
    // Superfluous comments are removed. @see #3110755 for examples and explanation.
    // Superfluous comments are removed. @see #3110755 for examples.
    $isLabelEnabled = $settings['day_format'] != 'none';
    $isTimeSlotEnabled = TRUE;
    $isCommentEnabled = $this->getFieldSetting('comment');
Loading