Completed
Pull Request — develop (#1165)
by Naveen
02:40
created
src/wordlift/mappings/data-source/class-acf-data-source.php 2 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -11,60 +11,60 @@
 block discarded – undo
11 11
 
12 12
 class Acf_Data_Source implements Abstract_Data_Source {
13 13
 
14
-	public function get_data( $identifier, $property_data, $type ) {
14
+    public function get_data( $identifier, $property_data, $type ) {
15 15
 
16
-		if ( ! function_exists( 'get_field' ) || ! function_exists( 'get_field_object' ) ) {
17
-			return array();
18
-		}
16
+        if ( ! function_exists( 'get_field' ) || ! function_exists( 'get_field_object' ) ) {
17
+            return array();
18
+        }
19 19
 
20
-		return $this->get_data_for_acf_field( $property_data['field_name'], $identifier, $type );
21
-	}
20
+        return $this->get_data_for_acf_field( $property_data['field_name'], $identifier, $type );
21
+    }
22 22
 
23
-	/**
24
-	 * Gets data from acf, format the data if it is a repeater field.
25
-	 *
26
-	 * @param $field_name string
27
-	 * @param $identifier int Identifier ( post id or term id )
28
-	 *
29
-	 * @return array|mixed
30
-	 */
31
-	private function get_data_for_acf_field( $field_name, $identifier, $type ) {
32
-		if ( $type === Jsonld_Converter::TERM ) {
33
-			$term = get_term( $identifier );
34
-			// Data fetching method for term is different.
35
-			$field_data = get_field_object( $field_name, $term );
36
-			$data       = get_field( $field_name, $term );
37
-		} else {
38
-			$field_data = get_field_object( $field_name, $identifier );
39
-			$data       = get_field( $field_name, $identifier );
40
-		}
41
-		// only process if it is a repeater field, else return the data.
42
-		if ( is_array( $field_data ) && array_key_exists( 'type', $field_data )
43
-		     && $field_data['type'] === 'repeater' ) {
44
-			/**
45
-			 * check if we have only one sub field, currently we only support one subfield,
46
-			 * so each repeater item should be checked if there is a single sub field.
47
-			 */
48
-			if ( is_array( $data ) &&
49
-			     count( $data ) > 0 &&
50
-			     count( array_keys( $data[0] ) ) === 1 ) {
51
-				$repeater_formatted_data = array();
52
-				foreach ( $data as $item ) {
53
-					$repeater_formatted_data = array_merge( $repeater_formatted_data, array_values( $item ) );
54
-				}
55
-				// Remove non unique values.
56
-				$repeater_formatted_data = array_unique( $repeater_formatted_data );
57
-				// Remove empty values
58
-				$repeater_formatted_data = array_filter( $repeater_formatted_data, function ( $item ) {
59
-					return is_array( $item ) || strlen( $item );
60
-				} );
23
+    /**
24
+     * Gets data from acf, format the data if it is a repeater field.
25
+     *
26
+     * @param $field_name string
27
+     * @param $identifier int Identifier ( post id or term id )
28
+     *
29
+     * @return array|mixed
30
+     */
31
+    private function get_data_for_acf_field( $field_name, $identifier, $type ) {
32
+        if ( $type === Jsonld_Converter::TERM ) {
33
+            $term = get_term( $identifier );
34
+            // Data fetching method for term is different.
35
+            $field_data = get_field_object( $field_name, $term );
36
+            $data       = get_field( $field_name, $term );
37
+        } else {
38
+            $field_data = get_field_object( $field_name, $identifier );
39
+            $data       = get_field( $field_name, $identifier );
40
+        }
41
+        // only process if it is a repeater field, else return the data.
42
+        if ( is_array( $field_data ) && array_key_exists( 'type', $field_data )
43
+             && $field_data['type'] === 'repeater' ) {
44
+            /**
45
+             * check if we have only one sub field, currently we only support one subfield,
46
+             * so each repeater item should be checked if there is a single sub field.
47
+             */
48
+            if ( is_array( $data ) &&
49
+                 count( $data ) > 0 &&
50
+                 count( array_keys( $data[0] ) ) === 1 ) {
51
+                $repeater_formatted_data = array();
52
+                foreach ( $data as $item ) {
53
+                    $repeater_formatted_data = array_merge( $repeater_formatted_data, array_values( $item ) );
54
+                }
55
+                // Remove non unique values.
56
+                $repeater_formatted_data = array_unique( $repeater_formatted_data );
57
+                // Remove empty values
58
+                $repeater_formatted_data = array_filter( $repeater_formatted_data, function ( $item ) {
59
+                    return is_array( $item ) || strlen( $item );
60
+                } );
61 61
 
62
-				// re-index all the values.
63
-				return array_values( $repeater_formatted_data );
64
-			}
65
-		}
62
+                // re-index all the values.
63
+                return array_values( $repeater_formatted_data );
64
+            }
65
+        }
66 66
 
67
-		// Return normal acf data if it is not a repeater field.
68
-		return $data;
69
-	}
67
+        // Return normal acf data if it is not a repeater field.
68
+        return $data;
69
+    }
70 70
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -11,13 +11,13 @@  discard block
 block discarded – undo
11 11
 
12 12
 class Acf_Data_Source implements Abstract_Data_Source {
13 13
 
14
-	public function get_data( $identifier, $property_data, $type ) {
14
+	public function get_data($identifier, $property_data, $type) {
15 15
 
16
-		if ( ! function_exists( 'get_field' ) || ! function_exists( 'get_field_object' ) ) {
16
+		if ( ! function_exists('get_field') || ! function_exists('get_field_object')) {
17 17
 			return array();
18 18
 		}
19 19
 
20
-		return $this->get_data_for_acf_field( $property_data['field_name'], $identifier, $type );
20
+		return $this->get_data_for_acf_field($property_data['field_name'], $identifier, $type);
21 21
 	}
22 22
 
23 23
 	/**
@@ -28,39 +28,39 @@  discard block
 block discarded – undo
28 28
 	 *
29 29
 	 * @return array|mixed
30 30
 	 */
31
-	private function get_data_for_acf_field( $field_name, $identifier, $type ) {
32
-		if ( $type === Jsonld_Converter::TERM ) {
33
-			$term = get_term( $identifier );
31
+	private function get_data_for_acf_field($field_name, $identifier, $type) {
32
+		if ($type === Jsonld_Converter::TERM) {
33
+			$term = get_term($identifier);
34 34
 			// Data fetching method for term is different.
35
-			$field_data = get_field_object( $field_name, $term );
36
-			$data       = get_field( $field_name, $term );
35
+			$field_data = get_field_object($field_name, $term);
36
+			$data       = get_field($field_name, $term);
37 37
 		} else {
38
-			$field_data = get_field_object( $field_name, $identifier );
39
-			$data       = get_field( $field_name, $identifier );
38
+			$field_data = get_field_object($field_name, $identifier);
39
+			$data       = get_field($field_name, $identifier);
40 40
 		}
41 41
 		// only process if it is a repeater field, else return the data.
42
-		if ( is_array( $field_data ) && array_key_exists( 'type', $field_data )
43
-		     && $field_data['type'] === 'repeater' ) {
42
+		if (is_array($field_data) && array_key_exists('type', $field_data)
43
+		     && $field_data['type'] === 'repeater') {
44 44
 			/**
45 45
 			 * check if we have only one sub field, currently we only support one subfield,
46 46
 			 * so each repeater item should be checked if there is a single sub field.
47 47
 			 */
48
-			if ( is_array( $data ) &&
49
-			     count( $data ) > 0 &&
50
-			     count( array_keys( $data[0] ) ) === 1 ) {
48
+			if (is_array($data) &&
49
+			     count($data) > 0 &&
50
+			     count(array_keys($data[0])) === 1) {
51 51
 				$repeater_formatted_data = array();
52
-				foreach ( $data as $item ) {
53
-					$repeater_formatted_data = array_merge( $repeater_formatted_data, array_values( $item ) );
52
+				foreach ($data as $item) {
53
+					$repeater_formatted_data = array_merge($repeater_formatted_data, array_values($item));
54 54
 				}
55 55
 				// Remove non unique values.
56
-				$repeater_formatted_data = array_unique( $repeater_formatted_data );
56
+				$repeater_formatted_data = array_unique($repeater_formatted_data);
57 57
 				// Remove empty values
58
-				$repeater_formatted_data = array_filter( $repeater_formatted_data, function ( $item ) {
59
-					return is_array( $item ) || strlen( $item );
58
+				$repeater_formatted_data = array_filter($repeater_formatted_data, function($item) {
59
+					return is_array($item) || strlen($item);
60 60
 				} );
61 61
 
62 62
 				// re-index all the values.
63
-				return array_values( $repeater_formatted_data );
63
+				return array_values($repeater_formatted_data);
64 64
 			}
65 65
 		}
66 66
 
Please login to merge, or discard this patch.