avatar.php
4 months ago
boolean.php
4 months ago
code.php
4 months ago
color.php
4 months ago
comment.php
4 months ago
currency.php
4 months ago
date.php
4 months ago
datetime.php
4 months ago
email.php
4 months ago
file.php
4 months ago
heading.php
4 months ago
html.php
4 months ago
link.php
4 months ago
number.php
4 months ago
oembed.php
4 months ago
paragraph.php
4 months ago
password.php
4 months ago
phone.php
4 months ago
pick.php
4 months ago
slug.php
4 months ago
taxonomy.php
4 months ago
text.php
4 months ago
time.php
4 months ago
website.php
4 months ago
wysiwyg.php
4 months ago
slug.php
131 lines
| 1 | <?php |
| 2 | |
| 3 | // Don't load directly. |
| 4 | if ( ! defined( 'ABSPATH' ) ) { |
| 5 | die( '-1' ); |
| 6 | } |
| 7 | |
| 8 | /** |
| 9 | * @package Pods\Fields |
| 10 | */ |
| 11 | class PodsField_Slug extends PodsField { |
| 12 | |
| 13 | /** |
| 14 | * {@inheritdoc} |
| 15 | */ |
| 16 | public static $type = 'slug'; |
| 17 | |
| 18 | /** |
| 19 | * {@inheritdoc} |
| 20 | */ |
| 21 | public static $label = 'Permalink (url-friendly)'; |
| 22 | |
| 23 | /** |
| 24 | * {@inheritdoc} |
| 25 | */ |
| 26 | public static $prepare = '%s'; |
| 27 | |
| 28 | /** |
| 29 | * {@inheritdoc} |
| 30 | */ |
| 31 | public static $pod_types = [ |
| 32 | 'pod', |
| 33 | 'table', |
| 34 | ]; |
| 35 | |
| 36 | /** |
| 37 | * {@inheritdoc} |
| 38 | */ |
| 39 | public function setup() { |
| 40 | |
| 41 | static::$label = __( 'Permalink (url-friendly)', 'pods' ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * {@inheritdoc} |
| 46 | */ |
| 47 | public function options() { |
| 48 | |
| 49 | $options = [ |
| 50 | static::$type . '_placeholder' => [ |
| 51 | 'label' => __( 'HTML Placeholder', 'pods' ), |
| 52 | 'default' => '', |
| 53 | 'type' => 'text', |
| 54 | 'help' => [ |
| 55 | __( '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' ), |
| 56 | 'https://www.w3.org/WAI/tutorials/forms/instructions/#placeholder-text', |
| 57 | ], |
| 58 | ], |
| 59 | ]; |
| 60 | |
| 61 | return $options; |
| 62 | |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * {@inheritdoc} |
| 67 | */ |
| 68 | public function schema( $options = null ) { |
| 69 | |
| 70 | $schema = 'VARCHAR(200)'; |
| 71 | |
| 72 | return $schema; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * {@inheritdoc} |
| 77 | */ |
| 78 | public function input( $name, $value = null, $options = null, $pod = null, $id = null ) { |
| 79 | |
| 80 | $options = ( is_array( $options ) || is_object( $options ) ) ? $options : (array) $options; |
| 81 | $form_field_type = PodsForm::$field_type; |
| 82 | |
| 83 | $value = $this->normalize_value_for_input( $value, $options, '-' ); |
| 84 | |
| 85 | $field_type = 'slug'; |
| 86 | |
| 87 | if ( isset( $options['name'] ) && ! pods_permission( $options ) ) { |
| 88 | if ( pods_v_bool( 'read_only_restricted', $options ) ) { |
| 89 | $options['readonly'] = true; |
| 90 | |
| 91 | $field_type = 'text'; |
| 92 | } else { |
| 93 | return; |
| 94 | } |
| 95 | } elseif ( ! pods_has_permissions( $options ) ) { |
| 96 | if ( pods_v_bool( 'read_only', $options ) ) { |
| 97 | $options['readonly'] = true; |
| 98 | |
| 99 | $field_type = 'text'; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | if ( ! empty( $options['disable_dfv'] ) ) { |
| 104 | return pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) ); |
| 105 | } |
| 106 | |
| 107 | $type = pods_v( 'type', $options, static::$type ); |
| 108 | |
| 109 | $args = compact( array_keys( get_defined_vars() ) ); |
| 110 | $args = (object) $args; |
| 111 | |
| 112 | $this->render_input_script( $args ); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * {@inheritdoc} |
| 117 | */ |
| 118 | public function pre_save( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { |
| 119 | |
| 120 | $index = pods_v( 'pod_index', pods_v( 'options', $pod, $pod, true ), 'id', true ); |
| 121 | |
| 122 | if ( empty( $value ) && isset( $fields[ $index ] ) ) { |
| 123 | $value = $fields[ $index ]['value']; |
| 124 | } |
| 125 | |
| 126 | $value = pods_unique_slug( $value, $name, $pod, 0, $params->id, null, false ); |
| 127 | |
| 128 | return $value; |
| 129 | } |
| 130 | } |
| 131 |