Before I post a patch I thought I would post it here to vet out the best way to do this.

If we change function theme_paragraphs_field_multiple_value_form($variables) { and make &$variables a reference then you would be able to call: hook_preprocess_paragraphs_field_multiple_value_form(&$vars) and just create the text you want.

$vars['add_text'] = 'This is my new text.';

or

$add_text = variable_get('paragraphs_add_more_text', NULL);

and let others just set a variable.

This would need to change a bit as well

$output = '<div class="form-item">';
  if (count($items)) {
    $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => $table_id, 'class' => array('field-multiple-table'))));
  }
  else {
    $output .= '<label>' . t('!title !required', array('!title' => $element['#title'], '!required' => $required)) . "</label>";
    if (isset($add_text)) {
      $output .= '<p><em>' . t($add_text) . '</em></p>';
    }
    else {
      if ($add_mode == 'button') {
        $add_text = 'No !title_multiple added yet, press a button below to add one.';
      }
      else {
        $add_text = 'No !title_multiple added yet. Select a !title type and press the button below to add one.';
      }
      $output .= '<p><em>' . t($add_text, array('!title_multiple' => t($instance['settings']['title_multiple']), '!title' => t($instance['settings']['title']))) . '</em></p>';
    }
  }
  $output .= $element['#description'] ? '<div class="description">' . $element['#description'] . '</div>' : '';
  $output .= '<div class="clearfix">' . drupal_render($add_more_button_type) . drupal_render($add_more_button) . '</div>';
  $output .= '</div>';

Let me know what you think, I need to patch this for OA.

Thanks

-Scott

Comments

scottalan’s picture

Issue summary: View changes
scottalan’s picture

Issue summary: View changes
nevets’s picture

I would like to see this as a field setting, so each paragraph field could have there own unique text with html allowed.

scottalan’s picture

Assigned: Unassigned » scottalan
scottalan’s picture

Here's a patch. Let me know if you feel anything needs to be changed.

Thanks,

-Scott

jeroen.b’s picture

Can you add backwards compatibility and a default value? (Existing fields should stay the same after an update)

nevets’s picture

Works for me, some suggested changes.

Use a textarea instead of textfield, it will allow for more visible text. I did this plus set '#rows' to 3.
I changed the title to 'Paragraph Instructions' since 'Help text' already appears on the form as part of core.
And I changed the description so instead of starting with 'This', it starts with 'When there are no existing paragraphs, this' to make it clearer when the text is show. End result for the element is

  $element['add_mode_help_text'] = array(
    '#type' => 'textarea',
    '#title' => t('Paragraph Instructions'),
    '#rows' => 3,
    '#description' => t('When there are no existing paragraphs, this text is displayed above the select list or buttons. e.g., "No Paragraphs added yet, press a button below to add one."'),
    '#default_value' => isset($settings['add_mode_help_text']) ? $settings['add_mode_help_text'] : '',
  );
scottalan’s picture

I have a new patch ready. I'll get it up later this morning, thanks!

scottalan’s picture

This patch will allow backwards compatibility. I added another settings field to handle actually hiding the 'Paragraph instructions' all together. This field seemed necessary since the default was to display the text. I can't base it off of the fact the Paragraph instruction textarea is empty. This provides a simple checkbox that allows hiding the instructions.

mpotter’s picture

Status: Active » Needs review

We are using this in Open Atrium, so setting correct status for other review. Would be good to get this in the next release.

jeroen.b’s picture

Status: Needs review » Needs work

Anyone wants to re-roll? Code looks fine to me.

mpotter’s picture

Status: Needs work » Needs review
StatusFileSize
new3.26 KB

I think this is a good re-roll against the latest dev and also adds a missing check_plain from #9 and changes the !var to @var as in the current dev.

mpotter’s picture

+++ b/paragraphs.module
@@ -1222,18 +1237,27 @@ function theme_paragraphs_field_multiple_value_form($variables) {
+        $add_text = 'No @title_multiple added yet. Select a !title type and press the button below to add one.';

Looks like I missed changing !title to @title here and on the line below.

mpotter’s picture

Here is a reroll against 1.0-rc5 that also fixes the comment in #13.

Status: Needs review » Needs work

The last submitted patch, 14: paragraphs-instructions_setting-2458801-14.patch, failed testing.

jeroen.b’s picture

Assigned: scottalan » jeroen.b

We are working on a test for this now.

jeffm2001’s picture

Re-rolled this patch against the latest dev

bluegeek9’s picture

Assigned: jeroen.b » Unassigned
Status: Needs work » Closed (outdated)
//www.flaticon.com/free-icons/thank-you Thank you for your contribution!

Unfortunately, Drupal 7 is End of Life and no longer supported. We strongly encourage you to upgrade to a supported version of Drupal.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.