-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlterGridFieldsData.php
76 lines (69 loc) · 1.89 KB
/
AlterGridFieldsData.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* Copyright (c) 2021. Geniem Oy
*/
use TMS\Theme\Base\Logger;
/**
* Alter Grid Fields block, layout
*/
class AlterGridFields {
/**
* Constructor
*/
public function __construct() {
add_filter(
'tms/block/grid/fields',
[ $this, 'alter_fields' ],
10,
2
);
add_filter(
'tms/acf/layout/_grid/fields',
[ $this, 'alter_fields' ],
10,
2
);
add_filter(
'tms/acf/block/grid/data',
[ $this, 'alter_format' ],
20
);
add_filter(
'tms/acf/layout/grid/data',
[ $this, 'alter_format' ],
20
);
}
/**
* Alter fields
*
* @param array $fields Array of ACF fields.
*
* @return array
*/
public function alter_fields( array $fields ) : array {
try {
$fields['repeater']->sub_fields['grid_item_custom']->sub_fields['description']->set_maxlength( 300 );
$fields['repeater']->sub_fields['grid_item_custom']->sub_fields['description']->set_new_lines( 'br' );
}
catch ( Exception $e ) {
( new Logger() )->error( $e->getMessage(), $e->getTrace() );
}
return $fields;
}
/**
* Format layout data. Replace BG colors.
*
* @param array $layout ACF Layout data.
*
* @return array
*/
public function alter_format( array $layout ) : array {
foreach ( $layout['repeater'] as $key => $item ) {
$layout['repeater'][ $key ]['classes'] = str_replace( [ 'has-colors-primary'], [ 'has-colors-secondary' ], $layout['repeater'][ $key ]['classes'] ); // phpcs:ignore
$layout['repeater'][ $key ]['button'] = 'is-primary has-text-weight-semibold';
}
return $layout;
}
}
( new AlterGridFields() );