You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+51-33Lines changed: 51 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ Require this package, with Composer, in the root directory of your project.
26
26
composer require wordplate/acf
27
27
```
28
28
29
-
Download the [Advanced Custom Fields Pro](https://www.advancedcustomfields.com/pro) plugin and put it in either the `plugins` or `mu-plugins` directory. Visit the WordPress dashboard and activate the plugin. Please note that you'll need the latest version of ACF in order to use all features in this package.
29
+
Download the [Advanced Custom Fields Pro](https://www.advancedcustomfields.com/pro) plugin and put it in either the `plugins` or `mu-plugins` directory. Visit the WordPress dashboard and activate the plugin.
Further down this page you'll find a list of available field types. Setting such as `wrapper`, `append` and `prepend` are supported on almost all fields but not listed in the documentation below. [Visit the official documentation](https://www.advancedcustomfields.com/resources/register-fields-via-php#field-settings) to read more about field settings.
95
-
96
94
### Basic Fields
97
95
98
96
**Email** - The [email field](https://www.advancedcustomfields.com/resources/text) creates a simple email input.
@@ -250,7 +248,7 @@ use WordPlate\Acf\Fields\TrueFalse;
->instructions('Select whether to display social media links or not.')
252
250
->defaultValue(false)
253
-
->stylisedUi() // optinal on and off text labels
251
+
->stylisedUi() // optional on and off text labels
254
252
->required();
255
253
```
256
254
@@ -414,24 +412,25 @@ Accordion::make('Endpoint')
414
412
415
413
**Clone** - The [clone field](https://www.advancedcustomfields.com/resources/clone) allows you to select and display existing fields or groups. This field doesn't have a custom field class. Instead create a new file with your field and import it using `require` where you need it.
416
414
417
-
-`occupation.php`
415
+
`occupation.php`
416
+
417
+
```php
418
+
use WordPlate\Acf\Fields\Text;
418
419
419
-
```php
420
-
use WordPlate\Acf\Fields\Text;
420
+
return Text::make('Occupation')
421
+
->instructions('Add the employees occupation.')
422
+
->required();
423
+
```
421
424
422
-
return Text::make('Occupation')
423
-
->instructions('Add the employees occupation.')
424
-
->required();
425
-
```
426
-
-`employee.php`
425
+
`employee.php`
427
426
428
-
```php
429
-
register_extended_field_group([
430
-
'fields' => [
431
-
require __DIR__.'/fields/occupation.php';
432
-
]
433
-
]);
434
-
```
427
+
```php
428
+
register_extended_field_group([
429
+
'fields' => [
430
+
require __DIR__.'/fields/occupation.php';
431
+
]
432
+
]);
433
+
```
435
434
436
435
**Flexible Content** - The [flexible content field](https://www.advancedcustomfields.com/resources/flexible-content) acts as a blank canvas to which you can add an unlimited number of layouts with full control over the order.
437
436
```php
@@ -598,22 +597,22 @@ User::make('User')
598
597
])
599
598
->returnFormat('array'); // id, object or array (default)
600
599
601
-
// Available roles are administrator, author, subscriber, contributor and editor. Deafult is no filter.
600
+
// Available roles are administrator, author, subscriber, contributor and editor. Default is no filter.
602
601
```
603
602
604
603
## Location
605
604
606
-
The location class let you write [custom location rules](https://www.advancedcustomfields.com/resources/custom-location-rules) without the `name`, `operator` and `value` keys. If no `operator` is given it will use the `operator` as the `key`.
605
+
The location class let you write [custom location rules](https://www.advancedcustomfields.com/resources/custom-location-rules) without the `name`, `operator` and `value` keys. If no `operator` is given it will use the `operator` as the `value`.
The conditional class help you write conditional logic [without knowing](https://media.giphy.com/media/SbtWGvMSmJIaV8faS8/source.gif) the fields `key` value.
615
+
The conditional class help you write conditional logic [without knowing](https://media.giphy.com/media/SbtWGvMSmJIaV8faS8/source.gif) the field keys.
617
616
618
617
```php
619
618
use WordPlate\Acf\ConditionalLogic;
@@ -628,17 +627,17 @@ Select::make('Type')
628
627
]),
629
628
File::make('Document', 'file')
630
629
->conditionalLogic([
631
-
ConditionalLogic::if('type')->equals('document')
630
+
ConditionalLogic::where('type', '==', 'document') // available operators are ==, !=, >, < ==pattern, ==contains, ==empty, !=empty
632
631
]),
633
632
Url::make('Link', 'url')
634
633
->conditionalLogic([
635
-
ConditionalLogic::if('type')->equals('link')
634
+
ConditionalLogic::where('type', '==', 'link')
636
635
]),
637
636
```
638
637
639
638
## Custom Configuration
640
639
641
-
If your application use third-party plugins which extend the default fields, you can extend the field classes in this package. Lets say you've want to add a configuration key to the select field. Create a new class which extends the base `WordPlate\Acf\Fields\Select` class:
640
+
If you want to add custom settings to the fields, you can extend the field classes available in this library.
642
641
643
642
```php
644
643
namespace App\Fields;
@@ -658,27 +657,46 @@ class Select extends Field
658
657
659
658
## Custom Fields
660
659
661
-
If your application use fields which isn't a default field in ACF, you may extend and create custom field classes. Lets say you've a field for Open Street Map. Create a new class which extends the base `WordPlate\Acf\Fields\Field` class:
660
+
If you want to create custom field classes you may extend the [base field class](src/Fields/Field.php). You may also import [available setting traits](src/Fields/Settings) in order to add common methods such as `required()` and `intstructions()`.
662
661
663
662
```php
664
663
namespace App\Fields;
665
664
666
665
use WordPlate\Acf\Fields\Field;
667
-
use WordPlate\Acf\Fields\Attributes\Instructions;
668
-
use WordPlate\Acf\Fields\Attributes\Required;
666
+
use WordPlate\Acf\Fields\Settings\Instructions;
667
+
use WordPlate\Acf\Fields\Settings\Required;
669
668
670
669
class OpenStreetMap extends Field
671
670
{
672
671
use Instructions;
673
672
use Required;
674
673
675
674
protected $type = 'open_street_map';
675
+
676
+
public function latitude(float $latitude): static
677
+
{
678
+
$this->settings['latitude'] = $latitude;
679
+
680
+
return $this;
681
+
}
682
+
683
+
public function longitude(float $longitude): static
684
+
{
685
+
$this->settings['longitude'] = $longitude;
686
+
687
+
return $this;
688
+
}
689
+
690
+
public function zoom(float $zoom): static
691
+
{
692
+
$this->settings['zoom'] = $zoom;
693
+
694
+
return $this;
695
+
}
676
696
}
677
697
```
678
698
679
-
Notice that we've imported traits which include the `required()` and `instructions()` methods. We've also added the `$type` property in order to let ACF know which field we're working with. You may now add any additional methods to this class which you will need such as `latitude()`, `longitude()`, `zoom()`, etc.
680
-
681
-
When you're ready you can import use it like any other field included in this package:
699
+
When you're ready you can import use your field like any other field available in this library:
0 commit comments