1.20.x field.block.inc FieldBlock::getAdminPreview()

Sets description text on draggable block in Layout builder.

Overrides Block::getAdminPreview

File

modules/field/field.block.inc, line 36

Class

FieldBlock
FieldBlock extends Block

Code

function getAdminPreview() {
  if (!empty($this->settings['admin_description'])) {
    return filter_xss($this->settings['admin_description']);
  }

  list($entity_type, $field_name) = explode('-', $this->childDelta, 2);
  $field = field_info_field($field_name);

  $formatter_name = $this->settings['formatter'];
  $formatter = field_info_formatter_types($formatter_name);
  $default_formatter_settings = $formatter['settings'];
  $formatter_settings = array_merge($default_formatter_settings, $this->settings['formatter_settings']);
  $pseudo_instance = $this->createPseudoInstance($formatter_name, $formatter_settings);

  $summary = module_invoke($formatter['module'], 'field_formatter_settings_summary', $field, $pseudo_instance, '_custom');
  $preview = '<p>' . t('Displays values of the %field field.', array('%field' => $field_name)) . '</p>';
  $preview .= '<div class="field-formatter-summary">' . $summary . '</div>';
  $preview .= $this->getAdminConditionsPreview();
  return $preview;
}