It is possible to use PHP code inside the markup field? I've tried but no success with 7x release.

CommentFileSizeAuthor
#3 markup-formats.patch2.1 KBbluetegu

Comments

break9’s picture

I would also be interested in this feature.

gwalliman’s picture

Based on the 6.x fix from #927982: PHP or Tokens in markup field?, this is how I got it working:

/**
 * Implementation of hook_field_settings_form().
 */
function markup_field_settings_form($field, $instance, $has_data) {
  $form = array();
  $settings = $field['settings'];
  $form['markup'] = array(
    '#type' => 'text_format',
    '#title' => t('Markup'),
    '#default_value' => isset($settings['markup']['value']) ? $settings['markup']['value'] : '',
    '#required' => TRUE,
    '#rows' => 15,
    '#description' => t('The markup to be displayed. Any HTML is legal here, so be careful not to break your page layout.'),
  );
  $form['instructions'] = array(
    '#markup' => htmlentities(t('This is a special field. It will output the markup below, unfiltered by the system, on the node/edit form for this content type. Consider wrapping any visible output in <div class="form-item"></div> to follow form standards.')),

    '#weight' => -1,
  );
  return $form;
}
/**
 * Implementation of hook_field_widget_form().
 */
function markup_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  $element += array(
    'markup' => array(
      '#type' => 'markup',
      '#markup' => check_markup($field['settings']['markup']['value'],$field['settings']['markup']['format'],FALSE),
    ),
  );
  return $element;
}
bluetegu’s picture

StatusFileSize
new2.1 KB

Thanks gwalliman,

The above changes worked for me. I added one line to set the default value to the format selected. A patch is attached.

Important note: Because the type of field is changed from text to text_format, once you update, you will not see the text in already existing markup fields, so be sure to copy these configurations to a safe place and reconfigure the markup fields after the patch.

j4’s picture

Amazing patch and thanks a ton for the tip! Works like a charm

Thanks
Jaya

bcostlow’s picture

Version: 7.x-1.x-dev » 7.x-1.1-beta1
Status: Active » Closed (fixed)

The 7.x-1.1-beta1 release adds support for input formats, which includes the functionality added in the patch at #3.

Vote_Sizing_Steve’s picture

Did Drupal core 7.24 update break this feature? I no longer see my php markup fields, and instead get a site error contact administrator message (sorry, not able to reproduce exact message now).