Passed
Push — master ( 78492a...4f268f )
by Paul
04:26
created

SiteReviewsFormWidget   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 57
ccs 0
cts 35
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A widget() 0 3 1
A form() 0 39 1
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Widgets;
4
5
use GeminiLabs\SiteReviews\Database;
6
use GeminiLabs\SiteReviews\Shortcodes\SiteReviewsFormShortcode;
7
use GeminiLabs\SiteReviews\Widgets\Widget;
8
9
class SiteReviewsFormWidget extends Widget
10
{
11
	/**
12
	 * @param array $instance
13
	 * @return void
14
	 */
15
	public function form( $instance )
16
	{
17
		$this->widgetArgs = glsr( SiteReviewsFormShortcode::class )->normalize( $instance );
18
		$terms = glsr( Database::class )->getTerms();
19
		$this->renderField( 'text', [
20
			'class' => 'widefat',
21
			'label' => __( 'Title', 'site-reviews' ),
22
			'name' => 'title',
23
		]);
24
		$this->renderField( 'textarea', [
25
			'class' => 'widefat',
26
			'label' => __( 'Description', 'site-reviews' ),
27
			'name' => 'description',
28
		]);
29
		$this->renderField( 'select', [
30
			'class' => 'widefat',
31
			'label' => __( 'Automatically assign a category', 'site-reviews' ),
32
			'name' => 'category',
33
			'options' => ['' => __( 'Do not assign a category', 'site-reviews' )] + $terms,
34
		]);
35
		$this->renderField( 'text', [
36
			'class' => 'widefat',
37
			'default' => '',
38
			'description' => sprintf( __( 'You may also enter %s to assign to the current post.', 'site-reviews' ), '<code>post_id</code>' ),
39
			'label' => __( 'Assign reviews to a custom page/post ID', 'site-reviews' ),
40
			'name' => 'assign_to',
41
		]);
42
		$this->renderField( 'text', [
43
			'class' => 'widefat',
44
			'label' => __( 'Enter any custom CSS classes here', 'site-reviews' ),
45
			'name' => 'class',
46
		]);
47
		$this->renderField( 'checkbox', [
48
			'name' => 'hide',
49
			'options' => [
50
				'email' => __( 'Hide the email field', 'site-reviews' ),
51
				'name'  => __( 'Hide the name field', 'site-reviews' ),
52
				'terms' => __( 'Hide the terms field', 'site-reviews' ),
53
				'title' => __( 'Hide the title field', 'site-reviews' ),
54
			],
55
		]);
56
	}
57
58
	/**
59
	 * @param array $args
60
	 * @param array $instance
61
	 * @return void
62
	 */
63
	public function widget( $args, $instance )
64
	{
65
		echo glsr( SiteReviewsFormShortcode::class )->build( $instance, $args );
66
	}
67
}
68