Currently, description is hard coded as "Widget" in /src/Plugin/Field/FieldFormatter/StripeCheckoutFormatter on line 86.

          // @todo Make configurable.
          'description' => 'Widget',

To make this configurable, we need a second second setting form field.

For this, I recommend changing the function:

  public static function defaultSettings() {
    return [
      'link_text' => 'Purchase - [price]',
    ] + parent::defaultSettings();
  }

  /**
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    return [
        'link_text' => [
          '#type' => 'textfield',
          '#description' => 'The text that will be displayed for the purchase button.',
          '#default value' => $this->getSetting('link_text'),
          '#required' => TRUE,
        ]
    ] + parent::settingsForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function settingsSummary() {
    $summary = [];
    $summary[] = $this->getSetting('link_text');

    return $summary;
  }

to:

  public static function defaultSettings() {
    return [
      'link_text' => 'Purchase - [price]',
      'description_text' => 'Widget',
    ] + parent::defaultSettings();
  }

  /**
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $form = parent::settingsForm($form, $form_state);
    
    $form['link_text'] = [
          '#type' => 'textfield',
          '#description' => 'The text that will be displayed for the purchase button.',
          '#default value' => $this->getSetting('link_text'),
          '#required' => TRUE,
        ]
    ];
    $form['description_text'] = [
          '#type' => 'textfield',
          '#description' => 'The text that will be displayed in the Stripe Checkout widget.',
          '#default value' => $this->getSetting('description_text'),
          '#required' => TRUE,
        ]
    ];        
  }

  /**
   * {@inheritdoc}
   */
  public function settingsSummary() {
    $summary = [];
    $summary[] = $this->getSetting('link_text');
    $summary[] = $this->getSetting('description_text');

    return $summary;
  }

Then:

          'description' => $this->getSetting('description_text'),

Patch forthcoming.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

scottsawyer created an issue. See original summary.

scottsawyer’s picture

And here's the patch. Didn't change as much as I initially thought.

One thing I noticed is there is no stripe_checkout.schema.yml for these two settings fields, 'link_text' and 'description_text'. It seems to work fine without them, but is recommended per https://www.drupal.org/docs/8/creating-custom-modules/create-a-custom-fi...

scottsawyer’s picture

For some reason, this patch conflicts with #2896528: Add configuration form for Stripe Field Formatter when installing via composer. Since that patch is more important ( IMO ), I think I'll just wait until that other issue is committed, then reroll this patch. The code actually works, so if you wanted to use it, it should be fine for now.

grasmash’s picture

Status: Active » Needs review