PluginProbe
Hash Form – Drag & Drop Form Builder / trunk
Hash Form – Drag & Drop Form Builder vtrunk
1.4.4 1.4.3 1.4.2 1.4.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.6.1 1.2.7 1.2.8 1.2.9 1.3.0 All 47 releases
hash-form / includes / fields / HashFormFieldHeading.php

HashFormFieldHeading.php in Hash Form – Drag & Drop Form Builder trunk, at includes/fields/HashFormFieldHeading.php

68 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') || die();
3
4 class HashFormFieldHeading extends HashFormFieldType {
5
6 protected $type = 'heading';
7
8 public function field_settings_for_type() {
9 return array(
10 'label' => false,
11 'default' => false,
12 'description' => false,
13 'label_position' => false,
14 'required' => false,
15 'content' => true,
16 'field_alignment' => true,
17 );
18 }
19
20 protected function extra_field_default_opts() {
21 return array(
22 // Not h1: the page a form sits in already has one, and a second
23 // breaks the document outline for anything reading the structure.
24 'heading_type' => 'h3',
25 'content' => 'Heading',
26 'text_alignment' => 'left',
27 'field_alignment' => 'left',
28 );
29 }
30
31 /**
32 * The tag to use, held to the six that exist.
33 *
34 * Worked out once and used for both ends of the element, rather than the
35 * same expression written twice with two chances to disagree.
36 */
37 private function heading_tag($field) {
38 $tag = isset($field['heading_type']) ? strtolower(trim($field['heading_type'])) : '';
39
40 return in_array($tag, hashform_heading_levels(), true) ? $tag : 'h3';
41 }
42
43 protected function input_html() {
44 $field = $this->get_field();
45 $content = isset($field['content']) ? $field['content'] : '';
46 $content = apply_filters('hashform_translate_string', $content, 'Hash Form', HashFormBuilder::get_form_title($field['form_id']) . ' - ' . $field['id'] . ' - ' . 'Field Content');
47
48 /*
49 * Headings stay one line of plain text. The content option is shared
50 * with the paragraph field, which does accept markup, so anything that
51 * arrives here is flattened rather than shown as literal tags.
52 */
53 $content = wp_strip_all_tags($content);
54
55 // An empty heading is an empty element in the page and an empty
56 // announcement to a screen reader, so it is not written at all.
57 if ('' === trim($content)) {
58 return;
59 }
60
61 $tag = $this->heading_tag($field);
62 ?>
63 <<?php echo esc_attr($tag); ?> class="hf-heading-field" id="hf-field-<?php echo absint($field['id']); ?>"><?php echo esc_html($content); ?></<?php echo esc_attr($tag); ?>>
64 <?php
65 }
66
67 }
68