Move widget field definitions to view files

This commit is contained in:
Robin Cornett
2018-03-29 16:28:46 -04:00
parent 6fe15a8b40
commit 4d42293e57
13 changed files with 296 additions and 350 deletions
@@ -29,7 +29,7 @@ class DisplayFeaturedImageGenesisWidgetsForm {
/**
* @return array
*/
protected function get_image_size() {
public function get_image_size() {
$sizes = genesis_get_image_sizes();
$options = array();
foreach ( (array) $sizes as $name => $size ) {
@@ -42,7 +42,7 @@ class DisplayFeaturedImageGenesisWidgetsForm {
/**
* @return array
*/
protected function get_image_alignment() {
public function get_image_alignment() {
return array(
'alignnone' => __( 'None', 'display-featured-image-genesis' ),
'alignleft' => __( 'Left', 'display-featured-image-genesis' ),
@@ -51,138 +51,6 @@ class DisplayFeaturedImageGenesisWidgetsForm {
);
}
/**
* Get image fields (used in CPT and term).
*
* @return array
*/
public function get_image_fields() {
return array(
array(
'method' => 'checkbox',
'args' => array(
'id' => 'show_image',
'label' => __( 'Show Featured Image', 'display-featured-image-genesis' ),
),
),
array(
'method' => 'select',
'args' => array(
'id' => 'image_size',
'label' => __( 'Image Size:', 'display-featured-image-genesis' ),
'flex' => true,
'choices' => $this->get_image_size(),
),
),
array(
'method' => 'select',
'args' => array(
'id' => 'image_alignment',
'label' => __( 'Image Alignment', 'display-featured-image-genesis' ),
'flex' => true,
'choices' => $this->get_image_alignment(),
),
),
);
}
/**
* Get the image fields for the author widget.
*
* @return array
*/
public function get_author_image_fields() {
return array(
array(
'method' => 'checkbox',
'args' => array(
'id' => 'show_featured_image',
'label' => __( 'Show the user\'s featured image.', 'display-featured-image-genesis' ),
),
),
array(
'method' => 'select',
'args' => array(
'id' => 'featured_image_size',
'label' => __( 'Image Size:', 'display-featured-image-genesis' ),
'flex' => true,
'choices' => $this->get_image_size(),
),
),
array(
'method' => 'select',
'args' => array(
'id' => 'featured_image_alignment',
'label' => __( 'Image Alignment:', 'display-featured-image-genesis' ),
'flex' => true,
'choices' => $this->get_image_alignment(),
),
),
);
}
/**
* Get the text fields (used in CPT and term).
*
* @return array
*/
public function get_text_fields() {
$label = 'featured-taxonomy' === $this->parent->id_base ? __( 'Term', 'display-featured-image-genesis' ) : __( 'Archive', 'display-featured-image-genesis' );
return array(
array(
'method' => 'checkbox',
'args' => array(
'id' => 'show_title',
'label' => sprintf( __( 'Show %s Title', 'display-featured-image-genesis' ), $label ),
),
),
array(
'method' => 'select',
'args' => array(
'id' => 'show_content',
'label' => sprintf( __( 'Show %s Intro Text', 'display-featured-image-genesis' ), $label ),
'choices' => array(
'' => __( 'None', 'display-featured-image-genesis' ),
1 => __( 'Intro Text', 'display-featured-image-genesis' ),
'custom' => __( 'Custom Text (below)', 'display-featured-image-genesis' ),
),
),
),
array(
'method' => 'textarea',
'args' => array(
'id' => 'custom_content',
'label' => __( 'Custom Intro Text', 'display-featured-image-genesis' ),
),
),
);
}
/**
* Get the archive fields (used in term and CPT widgets).
*
* @return array
*/
public function get_archive_fields() {
return array(
array(
'method' => 'checkbox',
'args' => array(
'id' => 'archive_link',
'label' => __( 'Show Archive Link', 'display-featured-image-genesis' ),
),
),
array(
'method' => 'text',
'args' => array(
'id' => 'archive_link_text',
'label' => __( 'Archive Link Text', 'display-featured-image-genesis' ),
),
),
);
}
/**
* Build boxes with fields.
*
@@ -223,10 +91,8 @@ class DisplayFeaturedImageGenesisWidgetsForm {
*/
public function do_fields( $instance, $fields ) {
foreach ( $fields as $field ) {
$method = "do_{$field['method']}";
if ( method_exists( $this, $method ) ) {
$this->$method( $instance, $field['args'] );
}
$args = $field['args'];
include $this->path( $field['method'] );
}
}
@@ -250,36 +116,6 @@ class DisplayFeaturedImageGenesisWidgetsForm {
include $this->path( 'select' );
}
/**
* Generic function to build a number input.
*
* @param $instance
* @param $args
*/
public function do_number( $instance, $args ) {
include $this->path( 'number' );
}
/**
* Generic function to build a checkbox input.
*
* @param $instance
* @param $args
*/
public function do_checkbox( $instance, $args ) {
include $this->path( 'checkbox' );
}
/**
* Generic function to build a textarea input
*
* @param $instance
* @param $args
*/
public function do_textarea( $instance, $args ) {
include $this->path( 'textarea' );
}
/**
* Get path for included files.
*
@@ -195,10 +195,10 @@ class Display_Featured_Image_Genesis_Author_Widget extends WP_Widget {
$form = new DisplayFeaturedImageGenesisWidgetsForm( $this, $new_instance );
return array_merge(
$form->get_author_image_fields(),
$this->get_gravatar_fields(),
$this->get_description_fields(),
$this->get_archive_fields()
include 'fields/author-image.php',
include 'fields/author-gravatar.php',
include 'fields/author-description.php',
include 'fields/author-archive.php'
);
}
@@ -226,132 +226,22 @@ class Display_Featured_Image_Genesis_Author_Widget extends WP_Widget {
) );
$form->do_boxes( array(
'author' => $form->get_author_image_fields(),
'author' => include 'fields/author-image.php',
), 'genesis-widget-column-box-top' );
$form->do_boxes( array(
'gravatar' => $this->get_gravatar_fields(),
'gravatar' => include 'fields/author-gravatar.php',
) );
$form->do_boxes( array(
'description' => $this->get_description_fields(),
'description' => include 'fields/author-description.php',
) );
$form->do_boxes( array(
'archive' => $this->get_archive_fields(),
'archive' => include 'fields/author-archive.php',
) );
}
/**
* Get the gravatar fields.
*
* @return array
*/
protected function get_gravatar_fields() {
return array(
array(
'method' => 'checkbox',
'args' => array(
'id' => 'show_gravatar',
'label' => __( 'Show the user\'s gravatar.', 'display-featured-image-genesis' ),
),
),
array(
'method' => 'select',
'args' => array(
'id' => 'size',
'label' => __( 'Gravatar Size:', 'display-featured-image-genesis' ),
'flex' => true,
'choices' => $this->get_gravatar_sizes(),
),
),
array(
'method' => 'select',
'args' => array(
'id' => 'gravatar_alignment',
'label' => __( 'Gravatar Alignment:', 'display-featured-image-genesis' ),
'flex' => true,
'choices' => array(
'' => __( 'None', 'display-featured-image-genesis' ),
'left' => __( 'Left', 'display-featured-image-genesis' ),
'right' => __( 'Right', 'display-featured-image-genesis' ),
),
),
),
);
}
/**
* Get the author description fields.
*
* @return array
*/
protected function get_description_fields() {
return array(
array(
'method' => 'select',
'args' => array(
'id' => 'author_info',
'label' => __( 'Text to use as the author description:', 'display-featured-image-genesis' ),
'flex' => true,
'choices' => array(
'' => __( 'None', 'display-featured-image-genesis' ),
'bio' => __( 'Author Bio (from profile)', 'display-featured-image-genesis' ),
'text' => __( 'Custom Text (below)', 'display-featured-image-genesis' ),
),
),
),
array(
'method' => 'textarea',
'args' => array(
'id' => 'bio_text',
'label' => __( 'Custom Text Content', 'display-featured-image-genesis' ),
'flex' => true,
'rows' => 6,
),
),
);
}
/**
* Get the archive fields.
*
* @return array
*/
protected function get_archive_fields() {
return array(
array(
'method' => 'select',
'args' => array(
'id' => 'page',
'label' => __( 'Choose your extended "About Me" page from the list below. This will be the page linked to at the end of the author description.', 'display-featured-image-genesis' ),
'choices' => $this->get_pages(),
),
),
array(
'method' => 'text',
'args' => array(
'id' => 'page_link_text',
'label' => __( 'Extended page link text', 'display-featured-image-genesis' ),
),
),
array(
'method' => 'checkbox',
'args' => array(
'id' => 'posts_link',
'label' => __( 'Show Author Archive Link?', 'display-featured-image-genesis' ),
),
),
array(
'method' => 'text',
'args' => array(
'id' => 'link_text',
'label' => __( 'Link Text:', 'display-featured-image-genesis' ),
),
),
);
}
/**
* Get the authors on the site.
*
@@ -319,10 +319,10 @@ class Display_Featured_Image_Genesis_Widget_CPT extends WP_Widget {
$form = new DisplayFeaturedImageGenesisWidgetsForm( $this, $instance );
return array_merge(
$this->get_post_type_fields(),
$form->get_text_fields(),
$form->get_image_fields(),
$form->get_archive_fields()
include 'fields/cpt-post_type.php',
include 'fields/text.php',
include 'fields/image.php',
include 'fields/archive.php'
);
}
@@ -346,41 +346,23 @@ class Display_Featured_Image_Genesis_Widget_CPT extends WP_Widget {
) );
$form->do_boxes( array(
'post_type' => $this->get_post_type_fields(),
'post_type' => include 'fields/cpt-post_type.php',
), 'genesis-widget-column-box-top' );
$label = __( 'Archive', 'display-featured-image-genesis' );
$form->do_boxes( array(
'words' => $form->get_text_fields(),
'words' => include 'fields/text.php',
) );
$form->do_boxes( array(
'image' => $form->get_image_fields(),
'image' => include 'fields/image.php',
) );
$form->do_boxes( array(
'archive' => $form->get_archive_fields(),
'archive' => include 'fields/archive.php',
) );
}
/**
* Get the post type fields.
*
* @return array
*/
protected function get_post_type_fields() {
return array(
array(
'method' => 'select',
'args' => array(
'id' => 'post_type',
'label' => __( 'Post Type:', 'display-featured-image-genesis' ),
'flex' => true,
'choices' => $this->get_post_types(),
),
),
);
}
/**
* Get the public registered post types on the site.
*
@@ -228,10 +228,10 @@ class Display_Featured_Image_Genesis_Widget_Taxonomy extends WP_Widget {
$form = new DisplayFeaturedImageGenesisWidgetsForm( $this, $instance );
return array_merge(
$form->get_text_fields(),
$this->get_taxonomy_fields( $instance ),
$form->get_image_fields(),
$form->get_archive_fields()
include 'fields/text.php',
include 'fields/term-taxonomy.php',
include 'fields/image.php',
include 'fields/archive.php'
);
}
@@ -257,51 +257,23 @@ class Display_Featured_Image_Genesis_Widget_Taxonomy extends WP_Widget {
) );
$form->do_boxes( array(
'taxonomy' => $this->get_taxonomy_fields( $instance ),
'taxonomy' => include 'fields/term-taxonomy.php',
), 'genesis-widget-column-box-top' );
$label = __( 'Term', 'display-featured-image-genesis' );
$form->do_boxes( array(
'words' => $form->get_text_fields(),
'words' => include 'fields/text.php',
) );
$form->do_boxes( array(
'image' => $form->get_image_fields(),
'image' => include 'fields/image.php',
), 'genesis-widget-column-box-top' );
$form->do_boxes( array(
'archive' => $form->get_archive_fields(),
'archive' => include 'fields/archive.php',
) );
}
/**
* @param $instance
*
* @return array
*/
protected function get_taxonomy_fields( $instance ) {
return array(
array(
'method' => 'select',
'args' => array(
'id' => 'taxonomy',
'label' => __( 'Taxonomy:', 'display-featured-image-genesis' ),
'flex' => true,
'onchange' => sprintf( 'term_postback(\'%s\', this.value );', esc_attr( $this->get_field_id( 'term' ) ) ),
'choices' => $this->get_taxonomies(),
),
),
array(
'method' => 'select',
'args' => array(
'id' => 'term',
'label' => __( 'Term:', 'display-featured-image-genesis' ),
'flex' => true,
'choices' => $this->get_term_lists( $instance, false ),
),
),
);
}
/**
* @return array
*/
+21
View File
@@ -0,0 +1,21 @@
<?php
/**
* Define archive fields.
*/
return array(
array(
'method' => 'checkbox',
'args' => array(
'id' => 'archive_link',
'label' => __( 'Show Archive Link', 'display-featured-image-genesis' ),
),
),
array(
'method' => 'text',
'args' => array(
'id' => 'archive_link_text',
'label' => __( 'Archive Link Text', 'display-featured-image-genesis' ),
),
),
);
@@ -0,0 +1,36 @@
<?php
/**
* Define author specific archive fields.
*/
return array(
array(
'method' => 'select',
'args' => array(
'id' => 'page',
'label' => __( 'Choose your extended "About Me" page from the list below. This will be the page linked to at the end of the author description.', 'display-featured-image-genesis' ),
'choices' => $this->get_pages(),
),
),
array(
'method' => 'text',
'args' => array(
'id' => 'page_link_text',
'label' => __( 'Extended page link text', 'display-featured-image-genesis' ),
),
),
array(
'method' => 'checkbox',
'args' => array(
'id' => 'posts_link',
'label' => __( 'Show Author Archive Link?', 'display-featured-image-genesis' ),
),
),
array(
'method' => 'text',
'args' => array(
'id' => 'link_text',
'label' => __( 'Link Text:', 'display-featured-image-genesis' ),
),
),
);
@@ -0,0 +1,29 @@
<?php
/**
* Define author specific desctiption fields.
*/
return array(
array(
'method' => 'select',
'args' => array(
'id' => 'author_info',
'label' => __( 'Text to use as the author description:', 'display-featured-image-genesis' ),
'flex' => true,
'choices' => array(
'' => __( 'None', 'display-featured-image-genesis' ),
'bio' => __( 'Author Bio (from profile)', 'display-featured-image-genesis' ),
'text' => __( 'Custom Text (below)', 'display-featured-image-genesis' ),
),
),
),
array(
'method' => 'textarea',
'args' => array(
'id' => 'bio_text',
'label' => __( 'Custom Text Content', 'display-featured-image-genesis' ),
'flex' => true,
'rows' => 6,
),
),
);
@@ -0,0 +1,36 @@
<?php
/**
* Define author specific gravatar fields.
*/
return array(
array(
'method' => 'checkbox',
'args' => array(
'id' => 'show_gravatar',
'label' => __( 'Show the user\'s gravatar.', 'display-featured-image-genesis' ),
),
),
array(
'method' => 'select',
'args' => array(
'id' => 'size',
'label' => __( 'Gravatar Size:', 'display-featured-image-genesis' ),
'flex' => true,
'choices' => $this->get_gravatar_sizes(),
),
),
array(
'method' => 'select',
'args' => array(
'id' => 'gravatar_alignment',
'label' => __( 'Gravatar Alignment:', 'display-featured-image-genesis' ),
'flex' => true,
'choices' => array(
'' => __( 'None', 'display-featured-image-genesis' ),
'left' => __( 'Left', 'display-featured-image-genesis' ),
'right' => __( 'Right', 'display-featured-image-genesis' ),
),
),
),
);
+32
View File
@@ -0,0 +1,32 @@
<?php
/**
* Define author specific image fields.
*/
return array(
array(
'method' => 'checkbox',
'args' => array(
'id' => 'show_featured_image',
'label' => __( 'Show the user\'s featured image.', 'display-featured-image-genesis' ),
),
),
array(
'method' => 'select',
'args' => array(
'id' => 'featured_image_size',
'label' => __( 'Image Size:', 'display-featured-image-genesis' ),
'flex' => true,
'choices' => $form->get_image_size(),
),
),
array(
'method' => 'select',
'args' => array(
'id' => 'featured_image_alignment',
'label' => __( 'Image Alignment:', 'display-featured-image-genesis' ),
'flex' => true,
'choices' => $form->get_image_alignment(),
),
),
);
+16
View File
@@ -0,0 +1,16 @@
<?php
/**
* Define CPT specific post type fields.
*/
return array(
array(
'method' => 'select',
'args' => array(
'id' => 'post_type',
'label' => __( 'Post Type:', 'display-featured-image-genesis' ),
'flex' => true,
'choices' => $this->get_post_types(),
),
),
);
+32
View File
@@ -0,0 +1,32 @@
<?php
/**
* Define image fields.
*/
return array(
array(
'method' => 'checkbox',
'args' => array(
'id' => 'show_image',
'label' => __( 'Show Featured Image', 'display-featured-image-genesis' ),
),
),
array(
'method' => 'select',
'args' => array(
'id' => 'image_size',
'label' => __( 'Image Size:', 'display-featured-image-genesis' ),
'flex' => true,
'choices' => $form->get_image_size(),
),
),
array(
'method' => 'select',
'args' => array(
'id' => 'image_alignment',
'label' => __( 'Image Alignment', 'display-featured-image-genesis' ),
'flex' => true,
'choices' => $form->get_image_alignment(),
),
),
);
+26
View File
@@ -0,0 +1,26 @@
<?php
/**
* Define term specific taxonomy fields.
*/
return array(
array(
'method' => 'select',
'args' => array(
'id' => 'taxonomy',
'label' => __( 'Taxonomy:', 'display-featured-image-genesis' ),
'flex' => true,
'onchange' => sprintf( 'term_postback(\'%s\', this.value );', esc_attr( $this->get_field_id( 'term' ) ) ),
'choices' => $this->get_taxonomies(),
),
),
array(
'method' => 'select',
'args' => array(
'id' => 'term',
'label' => __( 'Term:', 'display-featured-image-genesis' ),
'flex' => true,
'choices' => $this->get_term_lists( $instance, false ),
),
),
);
+38
View File
@@ -0,0 +1,38 @@
<?php
/**
* Define text fields.
*/
if ( ! isset( $label ) ) {
$label = '';
}
return array(
array(
'method' => 'checkbox',
'args' => array(
'id' => 'show_title',
/* translators: this will read Term or Archive */
'label' => sprintf( __( 'Show %s Title', 'display-featured-image-genesis' ), $label ),
),
),
array(
'method' => 'select',
'args' => array(
'id' => 'show_content',
/* translators: this will read Term or Archive */
'label' => sprintf( __( 'Show %s Intro Text', 'display-featured-image-genesis' ), $label ),
'choices' => array(
'' => __( 'None', 'display-featured-image-genesis' ),
1 => __( 'Intro Text', 'display-featured-image-genesis' ),
'custom' => __( 'Custom Text (below)', 'display-featured-image-genesis' ),
),
),
),
array(
'method' => 'textarea',
'args' => array(
'id' => 'custom_content',
'label' => __( 'Custom Intro Text', 'display-featured-image-genesis' ),
),
),
);