PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.1.4.3
Pods – Custom Content Types and Fields v3.1.4.3
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / classes / fields / slug.php
pods / classes / fields Last commit date
avatar.php 1 day ago boolean.php 1 day ago code.php 1 day ago color.php 1 day ago comment.php 1 day ago currency.php 1 day ago date.php 1 day ago datetime.php 1 day ago email.php 1 day ago file.php 1 day ago heading.php 1 day ago html.php 1 day ago link.php 1 day ago number.php 1 day ago oembed.php 1 day ago paragraph.php 1 day ago password.php 1 day ago phone.php 1 day ago pick.php 1 day ago slug.php 1 day ago taxonomy.php 1 day ago text.php 1 day ago time.php 1 day ago website.php 1 day ago wysiwyg.php 1 day ago
slug.php
124 lines
1 <?php
2
3 /**
4 * @package Pods\Fields
5 */
6 class PodsField_Slug extends PodsField {
7
8 /**
9 * {@inheritdoc}
10 */
11 public static $type = 'slug';
12
13 /**
14 * {@inheritdoc}
15 */
16 public static $label = 'Permalink (url-friendly)';
17
18 /**
19 * {@inheritdoc}
20 */
21 public static $prepare = '%s';
22
23 /**
24 * {@inheritdoc}
25 */
26 public static $pod_types = array(
27 'pod',
28 'table',
29 );
30
31 /**
32 * {@inheritdoc}
33 */
34 public function setup() {
35
36 static::$label = __( 'Permalink (url-friendly)', 'pods' );
37 }
38
39 /**
40 * {@inheritdoc}
41 */
42 public function options() {
43
44 $options = array(
45 static::$type . '_placeholder' => array(
46 'label' => __( 'HTML Placeholder', 'pods' ),
47 'default' => '',
48 'type' => 'text',
49 'help' => array(
50 __( 'Placeholders can provide instructions or an example of the required data format for a field. Please note: It is not a replacement for labels or description text, and it is less accessible for people using screen readers.', 'pods' ),
51 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text',
52 ),
53 ),
54 );
55
56 return $options;
57
58 }
59
60 /**
61 * {@inheritdoc}
62 */
63 public function schema( $options = null ) {
64
65 $schema = 'VARCHAR(200)';
66
67 return $schema;
68 }
69
70 /**
71 * {@inheritdoc}
72 */
73 public function input( $name, $value = null, $options = null, $pod = null, $id = null ) {
74
75 $options = ( is_array( $options ) || is_object( $options ) ) ? $options : (array) $options;
76 $form_field_type = PodsForm::$field_type;
77
78 $value = $this->normalize_value_for_input( $value, $options, '-' );
79
80 $field_type = 'slug';
81
82 if ( isset( $options['name'] ) && ! pods_permission( $options ) ) {
83 if ( pods_v( 'read_only', $options, false ) ) {
84 $options['readonly'] = true;
85
86 $field_type = 'text';
87 } else {
88 return;
89 }
90 } elseif ( ! pods_has_permissions( $options ) && pods_v( 'read_only', $options, false ) ) {
91 $options['readonly'] = true;
92
93 $field_type = 'text';
94 }
95
96 if ( ! empty( $options['disable_dfv'] ) ) {
97 return pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
98 }
99
100 $type = pods_v( 'type', $options, static::$type );
101
102 $args = compact( array_keys( get_defined_vars() ) );
103 $args = (object) $args;
104
105 $this->render_input_script( $args );
106 }
107
108 /**
109 * {@inheritdoc}
110 */
111 public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
112
113 $index = pods_v( 'pod_index', pods_v( 'options', $pod, $pod, true ), 'id', true );
114
115 if ( empty( $value ) && isset( $fields[ $index ] ) ) {
116 $value = $fields[ $index ]['value'];
117 }
118
119 $value = pods_unique_slug( $value, $name, $pod, 0, $params->id, null, false );
120
121 return $value;
122 }
123 }
124