Completed
Push — develop ( dd2c91...e970a6 )
by David
02:48
created
src/admin/class-wordlift-admin-author-element.php 2 patches
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -19,112 +19,112 @@
 block discarded – undo
19 19
  */
20 20
 class Wordlift_Admin_Author_Element implements Wordlift_Admin_Element {
21 21
 
22
-	/**
23
-	 * The {@link Wordlift_Publisher_Service} instance.
24
-	 *
25
-	 * @since  3.14.0
26
-	 * @access private
27
-	 * @var \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
28
-	 */
29
-	private $publisher_service;
30
-
31
-	/**
32
-	 * A {@link Wordlift_Admin_Select2_Element} instance.
33
-	 *
34
-	 * @since  3.14.0
35
-	 * @access private
36
-	 * @var \Wordlift_Admin_Select2_Element $select_element A {@link Wordlift_Admin_Select2_Element} instance.
37
-	 */
38
-	private $select_element;
39
-
40
-	/**
41
-	 * Create a {@link Wordlift_Admin_Person_Element} instance.
42
-	 *
43
-	 * @since 3.14.0
44
-	 *
45
-	 * @param \Wordlift_Publisher_Service     $publisher_service The {@link Wordlift_Publisher_Service} instance.
46
-	 * @param \Wordlift_Admin_Select2_Element $select_element    The {@link Wordlift_Admin_Select_Element} instance.
47
-	 */
48
-	function __construct( $publisher_service, $select_element ) {
49
-
50
-		$this->publisher_service = $publisher_service;
51
-
52
-		// Child elements.
53
-		$this->select_element = $select_element;
54
-
55
-	}
56
-
57
-	/**
58
-	 * @inheritdoc
59
-	 */
60
-	public function render( $args ) {
61
-
62
-		// Parse the arguments and merge with default values.
63
-		$params = wp_parse_args( $args, array(
64
-			'id'             => uniqid( 'wl-input-' ),
65
-			'name'           => uniqid( 'wl-input-' ),
66
-			'current_entity' => 0,
67
-		) );
68
-
69
-		$current_entity_id = $params['current_entity'];
70
-		$data              = $this->publisher_service->query();
71
-
72
-		// Set a default to show when no entity is associated and a way to unassign.
73
-		array_unshift( $data, array(
74
-			'id'            => '0',
75
-			'text'          => __( '<em>(none)</em>', 'wordlift' ),
76
-			'type'          => '',
77
-			'thumbnail_url' => plugin_dir_url( dirname( __FILE__ ) ) . 'images/pixel.png',
78
-		) );
79
-
80
-		// Finally do the render, passing along also the current selected entity
81
-		// id and the options data.
82
-		return $this->do_render( $params, $current_entity_id, $data );
83
-	}
84
-
85
-	/**
86
-	 * Render the `select` using the provided parameters.
87
-	 *
88
-	 * @since 3.14.0
89
-	 *
90
-	 * @param array $params          The array of parameters from the `render` function.
91
-	 * @param int   $current_post_id The currently selected {@link WP_Post} `id`.
92
-	 * @param array $data            An array of Select2 options.
93
-	 *
94
-	 * @return \Wordlift_Admin_Author_Element $this Return this element.
95
-	 */
96
-	protected function do_render( $params, $current_post_id, $data ) {
97
-
98
-		// Queue the script which will initialize the select and style it.
99
-		wp_enqueue_script( 'wl-author-element', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/author.js', array( 'wordlift-select2' ) );
100
-
101
-		// Prepare the URLs for entities which don't have logos.
102
-		$person_thumbnail_url       = plugin_dir_url( dirname( __FILE__ ) ) . 'images/person.png';
103
-		$organization_thumbnail_url = plugin_dir_url( dirname( __FILE__ ) ) . 'images/organization.png';
104
-
105
-		// Get the current post.
106
-		$current_post = $current_post_id ? get_post( $current_post_id ) : null;
107
-
108
-		// Finally render the Select.
109
-		$this->select_element->render( array(
110
-			// Id.
111
-			'id'                 => $params['id'],
112
-			// Name.
113
-			'name'               => $params['name'],
114
-			// The selected id.
115
-			'value'              => $current_post_id,
116
-			// The selected item (must be in the options for Select2 to display it).
117
-			'options'            => $current_post ? array( $current_post->ID => $current_post->post_title ) : array(),
118
-			// The list of available options.
119
-			'data'               => $data,
120
-			// The HTML template for each option.
121
-			'template-result'    => "<div class='wl-select2-result'><span class='wl-select2-thumbnail' style='background-image: url( <%= obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'>&nbsp;</span><span class='wl-select2'><%= obj.text %></span><span class='wl-select2-type'><%= obj.type %></span></div>",
122
-			// The HTML template for the selected option.
123
-			'template-selection' => "<div class='wl-select2-selection'><span class='wl-select2-thumbnail' style='background-image: url( <%= obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'>&nbsp;</span><span class='wl-select2'><%= obj.text %></span><span class='wl-select2-type'><%= obj.type %></span></div>",
124
-		) );
125
-
126
-		// Finally return the element instance.
127
-		return $this;
128
-	}
22
+    /**
23
+     * The {@link Wordlift_Publisher_Service} instance.
24
+     *
25
+     * @since  3.14.0
26
+     * @access private
27
+     * @var \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
28
+     */
29
+    private $publisher_service;
30
+
31
+    /**
32
+     * A {@link Wordlift_Admin_Select2_Element} instance.
33
+     *
34
+     * @since  3.14.0
35
+     * @access private
36
+     * @var \Wordlift_Admin_Select2_Element $select_element A {@link Wordlift_Admin_Select2_Element} instance.
37
+     */
38
+    private $select_element;
39
+
40
+    /**
41
+     * Create a {@link Wordlift_Admin_Person_Element} instance.
42
+     *
43
+     * @since 3.14.0
44
+     *
45
+     * @param \Wordlift_Publisher_Service     $publisher_service The {@link Wordlift_Publisher_Service} instance.
46
+     * @param \Wordlift_Admin_Select2_Element $select_element    The {@link Wordlift_Admin_Select_Element} instance.
47
+     */
48
+    function __construct( $publisher_service, $select_element ) {
49
+
50
+        $this->publisher_service = $publisher_service;
51
+
52
+        // Child elements.
53
+        $this->select_element = $select_element;
54
+
55
+    }
56
+
57
+    /**
58
+     * @inheritdoc
59
+     */
60
+    public function render( $args ) {
61
+
62
+        // Parse the arguments and merge with default values.
63
+        $params = wp_parse_args( $args, array(
64
+            'id'             => uniqid( 'wl-input-' ),
65
+            'name'           => uniqid( 'wl-input-' ),
66
+            'current_entity' => 0,
67
+        ) );
68
+
69
+        $current_entity_id = $params['current_entity'];
70
+        $data              = $this->publisher_service->query();
71
+
72
+        // Set a default to show when no entity is associated and a way to unassign.
73
+        array_unshift( $data, array(
74
+            'id'            => '0',
75
+            'text'          => __( '<em>(none)</em>', 'wordlift' ),
76
+            'type'          => '',
77
+            'thumbnail_url' => plugin_dir_url( dirname( __FILE__ ) ) . 'images/pixel.png',
78
+        ) );
79
+
80
+        // Finally do the render, passing along also the current selected entity
81
+        // id and the options data.
82
+        return $this->do_render( $params, $current_entity_id, $data );
83
+    }
84
+
85
+    /**
86
+     * Render the `select` using the provided parameters.
87
+     *
88
+     * @since 3.14.0
89
+     *
90
+     * @param array $params          The array of parameters from the `render` function.
91
+     * @param int   $current_post_id The currently selected {@link WP_Post} `id`.
92
+     * @param array $data            An array of Select2 options.
93
+     *
94
+     * @return \Wordlift_Admin_Author_Element $this Return this element.
95
+     */
96
+    protected function do_render( $params, $current_post_id, $data ) {
97
+
98
+        // Queue the script which will initialize the select and style it.
99
+        wp_enqueue_script( 'wl-author-element', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/author.js', array( 'wordlift-select2' ) );
100
+
101
+        // Prepare the URLs for entities which don't have logos.
102
+        $person_thumbnail_url       = plugin_dir_url( dirname( __FILE__ ) ) . 'images/person.png';
103
+        $organization_thumbnail_url = plugin_dir_url( dirname( __FILE__ ) ) . 'images/organization.png';
104
+
105
+        // Get the current post.
106
+        $current_post = $current_post_id ? get_post( $current_post_id ) : null;
107
+
108
+        // Finally render the Select.
109
+        $this->select_element->render( array(
110
+            // Id.
111
+            'id'                 => $params['id'],
112
+            // Name.
113
+            'name'               => $params['name'],
114
+            // The selected id.
115
+            'value'              => $current_post_id,
116
+            // The selected item (must be in the options for Select2 to display it).
117
+            'options'            => $current_post ? array( $current_post->ID => $current_post->post_title ) : array(),
118
+            // The list of available options.
119
+            'data'               => $data,
120
+            // The HTML template for each option.
121
+            'template-result'    => "<div class='wl-select2-result'><span class='wl-select2-thumbnail' style='background-image: url( <%= obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'>&nbsp;</span><span class='wl-select2'><%= obj.text %></span><span class='wl-select2-type'><%= obj.type %></span></div>",
122
+            // The HTML template for the selected option.
123
+            'template-selection' => "<div class='wl-select2-selection'><span class='wl-select2-thumbnail' style='background-image: url( <%= obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'>&nbsp;</span><span class='wl-select2'><%= obj.text %></span><span class='wl-select2-type'><%= obj.type %></span></div>",
124
+        ) );
125
+
126
+        // Finally return the element instance.
127
+        return $this;
128
+    }
129 129
 
130 130
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	 * @param \Wordlift_Publisher_Service     $publisher_service The {@link Wordlift_Publisher_Service} instance.
46 46
 	 * @param \Wordlift_Admin_Select2_Element $select_element    The {@link Wordlift_Admin_Select_Element} instance.
47 47
 	 */
48
-	function __construct( $publisher_service, $select_element ) {
48
+	function __construct($publisher_service, $select_element) {
49 49
 
50 50
 		$this->publisher_service = $publisher_service;
51 51
 
@@ -57,29 +57,29 @@  discard block
 block discarded – undo
57 57
 	/**
58 58
 	 * @inheritdoc
59 59
 	 */
60
-	public function render( $args ) {
60
+	public function render($args) {
61 61
 
62 62
 		// Parse the arguments and merge with default values.
63
-		$params = wp_parse_args( $args, array(
64
-			'id'             => uniqid( 'wl-input-' ),
65
-			'name'           => uniqid( 'wl-input-' ),
63
+		$params = wp_parse_args($args, array(
64
+			'id'             => uniqid('wl-input-'),
65
+			'name'           => uniqid('wl-input-'),
66 66
 			'current_entity' => 0,
67
-		) );
67
+		));
68 68
 
69 69
 		$current_entity_id = $params['current_entity'];
70 70
 		$data              = $this->publisher_service->query();
71 71
 
72 72
 		// Set a default to show when no entity is associated and a way to unassign.
73
-		array_unshift( $data, array(
73
+		array_unshift($data, array(
74 74
 			'id'            => '0',
75
-			'text'          => __( '<em>(none)</em>', 'wordlift' ),
75
+			'text'          => __('<em>(none)</em>', 'wordlift'),
76 76
 			'type'          => '',
77
-			'thumbnail_url' => plugin_dir_url( dirname( __FILE__ ) ) . 'images/pixel.png',
78
-		) );
77
+			'thumbnail_url' => plugin_dir_url(dirname(__FILE__)).'images/pixel.png',
78
+		));
79 79
 
80 80
 		// Finally do the render, passing along also the current selected entity
81 81
 		// id and the options data.
82
-		return $this->do_render( $params, $current_entity_id, $data );
82
+		return $this->do_render($params, $current_entity_id, $data);
83 83
 	}
84 84
 
85 85
 	/**
@@ -93,20 +93,20 @@  discard block
 block discarded – undo
93 93
 	 *
94 94
 	 * @return \Wordlift_Admin_Author_Element $this Return this element.
95 95
 	 */
96
-	protected function do_render( $params, $current_post_id, $data ) {
96
+	protected function do_render($params, $current_post_id, $data) {
97 97
 
98 98
 		// Queue the script which will initialize the select and style it.
99
-		wp_enqueue_script( 'wl-author-element', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/author.js', array( 'wordlift-select2' ) );
99
+		wp_enqueue_script('wl-author-element', plugin_dir_url(dirname(__FILE__)).'admin/js/1/author.js', array('wordlift-select2'));
100 100
 
101 101
 		// Prepare the URLs for entities which don't have logos.
102
-		$person_thumbnail_url       = plugin_dir_url( dirname( __FILE__ ) ) . 'images/person.png';
103
-		$organization_thumbnail_url = plugin_dir_url( dirname( __FILE__ ) ) . 'images/organization.png';
102
+		$person_thumbnail_url       = plugin_dir_url(dirname(__FILE__)).'images/person.png';
103
+		$organization_thumbnail_url = plugin_dir_url(dirname(__FILE__)).'images/organization.png';
104 104
 
105 105
 		// Get the current post.
106
-		$current_post = $current_post_id ? get_post( $current_post_id ) : null;
106
+		$current_post = $current_post_id ? get_post($current_post_id) : null;
107 107
 
108 108
 		// Finally render the Select.
109
-		$this->select_element->render( array(
109
+		$this->select_element->render(array(
110 110
 			// Id.
111 111
 			'id'                 => $params['id'],
112 112
 			// Name.
@@ -114,14 +114,14 @@  discard block
 block discarded – undo
114 114
 			// The selected id.
115 115
 			'value'              => $current_post_id,
116 116
 			// The selected item (must be in the options for Select2 to display it).
117
-			'options'            => $current_post ? array( $current_post->ID => $current_post->post_title ) : array(),
117
+			'options'            => $current_post ? array($current_post->ID => $current_post->post_title) : array(),
118 118
 			// The list of available options.
119 119
 			'data'               => $data,
120 120
 			// The HTML template for each option.
121 121
 			'template-result'    => "<div class='wl-select2-result'><span class='wl-select2-thumbnail' style='background-image: url( <%= obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'>&nbsp;</span><span class='wl-select2'><%= obj.text %></span><span class='wl-select2-type'><%= obj.type %></span></div>",
122 122
 			// The HTML template for the selected option.
123 123
 			'template-selection' => "<div class='wl-select2-selection'><span class='wl-select2-thumbnail' style='background-image: url( <%= obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'>&nbsp;</span><span class='wl-select2'><%= obj.text %></span><span class='wl-select2-type'><%= obj.type %></span></div>",
124
-		) );
124
+		));
125 125
 
126 126
 		// Finally return the element instance.
127 127
 		return $this;
Please login to merge, or discard this patch.