get_description(); $html .= ''; // Get post type details. $post_type = get_post_type_object( $this->post_type ); if ( ! $post_type ) { $html .= esc_html( sprintf( __( 'The requested post type %s does not exist.', 'gravityforms' ), $this->post_type ) ); } else { $post_singular = $post_type->labels->singular_name; $post_plural = $post_type->labels->name; $html = sprintf( '
%3$s
    ', $this->post_type, esc_attr( $this->name ), // field name, used in HTML attributes esc_html( $this->get_dropdown_label( $post_singular ) ), // form switcher label esc_html( $this->get_search_label( $post_plural ) ), // label for search field esc_attr( $this->get_value() ), empty( $this->get_value() ) ? 'gform-dropdown__control--placeholder' : '' ); } // If field failed validation, add error icon. $html .= $this->get_error_icon(); $html .= '
    '; return $html; } /** * Get the label for the dropdown. * * @since 2.6.2 * * @param string $singular Post type name (singular) * * @return string */ public function get_dropdown_label( $singular ) { if ( empty( $this->get_value() ) ) { // Translators: singular post type name (e.g. 'post'). return sprintf( __( 'Select a %s', 'gravityforms' ), $singular ); } $post_id = $this->get_value(); return get_the_title( $post_id ); } /** * Get the label for the search field. * * @since 2.6.2 * * @param string $plural Post type name (plural) * * @return string */ public function get_search_label( $plural ) { // Translators: plural post type name (e.g. 'post's). return sprintf( __( 'Search all %s', 'gravityforms' ), $plural ); } } Fields::register( 'post_select', '\Gravity_Forms\Gravity_Forms\Settings\Fields\Post_Select' );