Commit 9406c745 authored by Julian Pustkuchen's avatar Julian Pustkuchen
Browse files

Issue #3306047 by Anybody: Add missing comments and fix phpcs issues

parent 619919fe
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -45,8 +45,8 @@ plugins at Reports > Extra Field Plugins List.

Upgrading to 3.x
-------------
If you're upgrading from 8.x-1.x or 8.x-2.x you have to make some changes to your
custom Extra Field Display plugins!
If you're upgrading from 8.x-1.x or 8.x-2.x you have to make some changes to
your custom Extra Field Display plugins!
Sadly these breaking changes (BC) were required. See UPGRADE.md for details
and required code changes!

+6 −3
Original line number Diff line number Diff line
# Upgrading from extra_field_plus 1.x or 2.x to 3.x

extra_field_plus >= 3.x contains breaking changes due to misconceptions in earlier versions.
When upgrading to 3.x (from 8.x-2.x or 8.x-1.x) you have to adjust your ExtraFieldPlus Display Plugins to match the new static method names.
extra_field_plus >= 3.x contains breaking changes due to misconceptions in
earlier versions.
When upgrading to 3.x (from 8.x-2.x or 8.x-1.x) you have to adjust your
ExtraFieldPlus Display Plugins to match the new static method names.

For details see the related issues:
- https://www.drupal.org/project/extra_field_plus/issues/3305531
@@ -62,7 +64,8 @@ protected static function settingsSummary(string $field_id, string $entity_type_
~~~


To see some code examples, you may want to have a look into the extra_field_plus_example module:
To see some code examples, you may want to have a look into the
extra_field_plus_example module:
https://git.drupalcode.org/project/extra_field_plus/-/tree/3.x/modules/extra_field_plus_example/src/Plugin/ExtraField/Display

There you can see the deprecated old code and the new replacement code.
+10 −2
Original line number Diff line number Diff line
<?php

function photoswipe_update_4000() {
  \Drupal::messenger()->addStatus("IMPORTANT: extra_field_plus 3.x contains small BREAKING CHANGES due to misconceptions in earlier versions.\n
/**
 * @file
 * Install, update and uninstall functions for the extra_field_plus module.
 */

/**
 * IMPORTANT: extra_field_plus 3.x upgrade: BREAKING CHANGES!
 */
function extra_field_plus_update_4000() {
  \Drupal::messenger()->addStatus("IMPORTANT: extra_field_plus 3.x contains BREAKING CHANGES due to misconceptions in earlier versions.\n
    When upgrading to 3.x, you have to adjust your ExtraFieldPlus Display Plugins to match the new static method names.\n
    For details see https://git.drupalcode.org/project/extra_field_plus/-/blob/3.x/UPGRADE.md\n
    You may cancel this update and go back to the earlier version to read details first.");
+27 −12
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
 * Main file for extra_field_plus module.
 */

use Drupal\layout_builder\Plugin\Block\ExtraFieldBlock;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Routing\RouteMatchInterface;
@@ -184,8 +185,9 @@ function extra_field_plus_form_entity_view_display_edit_form_alter(array &$form,
        $storage = $user_input['fields'][$name]['settings_edit_form']['settings'];
        $form_state->set($name, $storage);
        $row['settings_edit'] = $settings_edit;
        // @todo: To show the changed values in summary, we'd have to get the
        // actual values from $storage here and use these for the $settings_summary.
        // @todo To show the changed values in summary, we'd have to get the
        // actual values from $storage here and use these for the
        // $settings_summary.
        // We could for example do this by calling
        // ::getExtraFieldSettingsSummary and passing the $form_state.
        // @see https://www.drupal.org/project/extra_field_plus/issues/3305762
@@ -277,16 +279,23 @@ function extra_field_plus_form_entity_view_display_edit_form_submit(array $form,
  }
}

// Layout builder support:

/**
 * Implements hook_form_alter().
 */
function extra_field_plus_form_alter(array &$form, FormStateInterface &$form_state, $form_id) {
  if (in_array($form_id, ['layout_builder_add_block','layout_builder_update_block'])) {
  // Layout builder support:
  if (in_array($form_id, [
      'layout_builder_add_block',
      'layout_builder_update_block'
    ])) {
    /** @var \Drupal\layout_builder\SectionComponent $component */
    $component = $form_state->getFormObject()->getCurrentComponent();
    list ($componentPluginId, $entity_type_id, $bundle, $field_name) = explode(\Drupal\layout_builder\Plugin\Block\ExtraFieldBlock::DERIVATIVE_SEPARATOR, $component->get('configuration')['id'], 4);
    [
      $componentPluginId,
      $entity_type_id,
      $bundle,
      $field_name,
    ] = explode(ExtraFieldBlock::DERIVATIVE_SEPARATOR, $component->get('configuration')['id'], 4);

    if ($componentPluginId === 'extra_field_block') {
      /** @var \Drupal\Core\Plugin\Context\Context $context */
@@ -295,7 +304,7 @@ function extra_field_plus_form_alter(array &$form, FormStateInterface &$form_sta
      $display = $context->getContextValue();
      $view_mode = $display->getMode();

      // @todo: We may use third party settings here later, once
      // @todo We may use third party settings here later, once
      // https://www.drupal.org/project/drupal/issues/3015152 is out:
      // $settings = $component->getThirdPartySetting('extra_field_plus', 'settings') ?? [];
      // until that we get values this way:
@@ -330,14 +339,20 @@ function extra_field_plus_form_alter(array &$form, FormStateInterface &$form_sta
 * @param \Drupal\Core\Form\FormStateInterface $form_state
 *   The form state object.
 */
function extra_field_plus_form_submit($form, FormStateInterface $form_state) {
function extra_field_plus_form_submit(array $form, FormStateInterface $form_state) {
  // Layout builder support:
  // Note: EntityDisplayBase components are quite different (array) from layout
  // builder components (objects)! So we have to handle their data differently.
  $settings = $form_state->getValue(['settings', 'third_party_settings', 'extra_field_plus', 'settings']) ?? [];
  $settings = $form_state->getValue([
    'settings',
    'third_party_settings',
    'extra_field_plus',
    'settings',
  ]) ?? [];
  /** @var \Drupal\layout_builder\SectionComponent $component */
  $component = $form_state->getFormObject()->getCurrentComponent();

  // @todo: We may use third party settings here later, once
  // @todo We may use third party settings here later, once
  // https://www.drupal.org/project/drupal/issues/3015152 is out:
  // $component->setThirdPartySetting('extra_field_plus', 'settings', $settings);
  // until that we set values this way:
@@ -345,7 +360,7 @@ function extra_field_plus_form_submit($form, FormStateInterface $form_state) {

  // /** @var \Drupal\layout_builder\Form\UpdateBlockForm $form_object */
  // $form_object = $form_state->getFormObject();

  // // Call doBuildForm since $this->block gets set based on config and there is no other way to modify the built object.
  // // Call doBuildForm since $this->block gets set based on config and
  // // there is no other way to modify the built object.
  // $form_object->doBuildForm($form, $form_state,  $form_object->getSectionStorage(), 0, $component);
}
+49 −0
Original line number Diff line number Diff line
@@ -39,7 +39,21 @@ class ExtraFieldPlusDisplayManager extends ExtraFieldDisplayManager implements E
  }

  /**
   * Returns the field setting with the given $key.
   *
   * @param string $pluginId
   *   The Plugin Id to load the settings from.
   * @param string $field_id
   *   The field id.
   * @param string $entity_type_id
   *   The entity type id, e.g. 'node'.
   * @param string $bundle
   *   The entity type bundle, e.g. 'artcile'.
   * @param string $view_mode
   *   The entity view mode, e.g. 'default', 'full', 'teaser' , ...
   *
   * @return array
   *   The setting array.
   */
  public function getSettings(string $pluginId, string $field_id, string $entity_type_id, string $bundle, string $view_mode = 'default'): array {
    $plugin = $this->getFieldPlugin($pluginId);
@@ -48,7 +62,22 @@ class ExtraFieldPlusDisplayManager extends ExtraFieldDisplayManager implements E
  }

  /**
   * Returns the field settings form.
   *
   * @param string $pluginId
   *   The Plugin Id to load the settings from.
   * @param string $field_id
   *   The field id.
   * @param string $entity_type_id
   *   The entity type id, e.g. 'node'.
   * @param string $bundle
   *   The entity type bundle, e.g. 'artcile'.
   * @param string $view_mode
   *   The entity view mode, e.g. 'default', 'full', 'teaser' , ...
   *
   * @return array
   *   The field settings form array.
   *   Example: [key_1 => [...], key_2 => [...], ...].
   */
  public function getSettingsForm(string $pluginId, string $field_id, string $entity_type_id, string $bundle, string $view_mode = 'default'): array {
    $plugin = $this->getFieldPlugin($pluginId);
@@ -57,7 +86,21 @@ class ExtraFieldPlusDisplayManager extends ExtraFieldDisplayManager implements E
  }

  /**
   * Returns the field settings summary.
   *
   * @param string $pluginId
   *   The Plugin Id to load the settings from.
   * @param string $field_id
   *   The field id.
   * @param string $entity_type_id
   *   The entity type id, e.g. 'node'.
   * @param string $bundle
   *   The entity type bundle, e.g. 'artcile'.
   * @param string $view_mode
   *   The entity view mode, e.g. 'default', 'full', 'teaser' , ...
   *
   * @return array
   *   The field settings summary render array.
   */
  public function getSettingsSummary(string $pluginId, string $field_id, string $entity_type_id, string $bundle, string $view_mode = 'default'): array {
    $plugin = $this->getFieldPlugin($pluginId);
@@ -66,7 +109,13 @@ class ExtraFieldPlusDisplayManager extends ExtraFieldDisplayManager implements E
  }

  /**
   * Helper function to return the field plugin by the given plugin id.
   *
   * @param string $pluginId
   *   The plugin id.
   *
   * @return ExtraFieldPlusDisplayInterface
   *   The extra field plus display plugin.
   */
  protected function getFieldPlugin(string $pluginId): ExtraFieldPlusDisplayInterface {
    // Add settings and settings Form:
Loading