balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

multiple-values.php (1396B)


      1 <?php
      2 /**
      3  * This class implements common methods used in fields which have multiple values
      4  * like checkbox list, autocomplete, etc.
      5  *
      6  * The difference when handling actions for these fields are the way they get/set
      7  * meta value. Briefly:
      8  * - If field is cloneable, value is saved as a single entry in the database
      9  * - Otherwise value is saved as multiple entries
     10  *
     11  * @package Meta Box
     12  */
     13 
     14 /**
     15  * Multiple values field class.
     16  */
     17 abstract class RWMB_Multiple_Values_Field extends RWMB_Field {
     18 	/**
     19 	 * Normalize parameters for field.
     20 	 *
     21 	 * @param array $field Field parameters.
     22 	 *
     23 	 * @return array
     24 	 */
     25 	public static function normalize( $field ) {
     26 		$field               = parent::normalize( $field );
     27 		$field['multiple']   = true;
     28 		$field['field_name'] = $field['id'];
     29 		if ( ! $field['clone'] ) {
     30 			$field['field_name'] .= '[]';
     31 		}
     32 
     33 		return $field;
     34 	}
     35 
     36 	/**
     37 	 * Format a single value for the helper functions. Sub-fields should overwrite this method if necessary.
     38 	 *
     39 	 * @param array    $field   Field parameters.
     40 	 * @param string   $value   The value.
     41 	 * @param array    $args    Additional arguments. Rarely used. See specific fields for details.
     42 	 * @param int|null $post_id Post ID. null for current post. Optional.
     43 	 *
     44 	 * @return string
     45 	 */
     46 	public static function format_single_value( $field, $value, $args, $post_id ) {
     47 		return $field['options'][ $value ];
     48 	}
     49 }