bobbingwide / field-block-for-acf-pro Goto Github PK
View Code? Open in Web Editor NEWField block for ACF PRO
Home Page: https://www.oik-plugins.com/oik-plugins/field-block-for-acf-pro/
License: GNU General Public License v2.0
Field block for ACF PRO
Home Page: https://www.oik-plugins.com/oik-plugins/field-block-for-acf-pro/
License: GNU General Public License v2.0
Update code and PHPUnit tests to run without problems in PHP 8.1 and 8.2
The acf-field-block plugin should be enabled as a free plugin downloadable from wordpress.org.
It should therefore be:
PHP
acf-field-block
l10n
block.json
This issue is to extract the acf-field
block logic from oik-testimonials to this new plugin.
After a while I realised that the acf-field block should be a single block plugin that didn't come with the oik-testimonials and acf-cycler baggage. So I cloned the oik-testimonials plugin to acf-field-block.
supports
attributesoik-testimonials/acf-field
block will be renamed to acf-field/acf-field
ACF_Field
classDetermine what needs to be done to cater for the ACF field types of accordion
, tab
, etc..
The Message, Accordion, Tab, Group, Repeater, Flexible Content and Clone field types are Layout field types.
Q: How are these supposed to appear on the front end?
A:
Having placed my Message field after Accordion I noticed that neither field has a name
.
So it would appear that the Message has overridden the Accordion which is why the accordion didn't appear in the list of fields.
Group is different... it has subfields.
I tried submitting acf-field-block to the WordPress plugin directory but it has been pended
without looking at the code as the chosen name is infringing on someone else's trademark and/or common brand name.
The recommendation is to change the plugin to: Field block for ACF, permalink field-block-for-acf
I don't know at this time what I should change the block name to.
Maybe I'll stick with oik-sb
for the prefix
Extend the ACF field block to support the display of the options page
Currently, if you want to display the label for a field and it's value it's necessary to use more than one block.
The first would be a paragraph block containing the required label, the second the acf field block.
eg The labels are in the first column, the values in the second.
This is a bit cumbersome.
It would be nice to request the block to display the label as well as the value.
It would also be nice to be able to override the value of label.
The generated HTML would change from
<div class="acf-field-field_64aa869f48df7 acf-type-text has-text-align- wp-block-acf-field-acf-field">Content for the Text field</div>
<div class="acf-field-field_64aa869f48df7 acf-type-text has-text-align- wp-block-acf-field-acf-field">
<div class="label">Text</div>
<div class="value">Content for the Text field</div>
</div>
This could easily be styled as a grid.
According to the documentation at https://www.advancedcustomfields.com/resources/google-map/
the Google Map field provides an interactive map interface for selecting a location.
This field type uses the Google Maps JS API to provide autocomplete searching, reverse geocoding lookup and an interactive marker.
The Google Maps API requires an API key.
ACF finds this using a filter function ( acf/fields/google_map/api
), passing in the values obtained from acf_get_setting()
, for both google_api_key
and google_api_client
.
The field type should only be supported when an API key is available.
One way of achieving this is to define a Google Maps Field group, which contains the text field for the API key, and is displayed on the ACF Options page(s).
This might require the plugin to call acf_add_options_page()
, to ensure an Options page is available, and to define the Google Maps field group.
Perhaps this can be achieved by the rendering logic when a field of this type is first encountered?!
For helper code see https://www.advancedcustomfields.com/resources/google-map/#google-maps-helper-code
When the ACF field block is displaying the taxonomy
field type, then after cloning, since the taxonomy term ID has not been updated, a Notice is displayed.
Notice: Trying to get property ‘name’ of non-object in /home/customer/www/oik-plugins.co.uk/public_html/wp-content/plugins/acf-field-block/includes/class-acf-field-block-renderer.php on line 739.
When I tried to use the ACF field type of message
the response from render()
was :288eh?
This output is produced when the request to get_field_object()
returns null.
2 things:
message
do not get assigned a field name.echo $this->field_name;
print_r($this->field_info);
echo ':';
echo $this->post_id;
echo 'eh?';
It would be nice if the field names could be sorted by field name, as in the screenshot below.
It would also be nice if the field names could be improved to indicate the field group to which the field is associated.
This is in addition to the Post types which are already shown.
Once this has been done it may no longer be necessary to display the raw field name and key value,
which is currently included in the select list when SCRIPT_DEBUG
is true.
In this example the first Range field is from the Clone group that's only applicable to CPT Block examples. For this particuar post and the block's context it's the second field that we need to pick.
v1.0.0 has been reviewed by the plugin team.
There are some changes to make, mostly for improved security.
ACF Pro has some of its own security improvements in v6.2.5 and will have some more changes planned.
Some of the field types have render methods that access array elements within the field.
They assume that a value has been entered.
When it hasn't then a Fatal error may occur
eg
Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, bool given in C:\apache\htdocs\wordpress\wp-content\plugins\acf-field-block\includes\class-acf-field-block-renderer.php:385
The logic should take these instances into account and return early when there's nothing to render.
This test should be performed within the rendering method.
While attempting to develop PHPUnit tests for the ACF field block I deactivated the Layout group that contained some cloned fields. The fields for this inactive group were still being included in the list of field names, overriding the original field called text
.
Fields from any group that has been marked as Inactive shouldn't be included in the selection list for the ACF field block
Before making any major changes to the ACF Field block plugin it makes sense to develop a set of in situ PHPUnit tests that can be used to confirm that the server side rendering of the block is working for each supported field type.
These tests can be run for each new version of ACF PRO, WordPress and whenever making changes.
While trying to develop PHPUnit tests for each field type I encountered a problem where the field name Text
was being displayed for the wrong post type.
test-acf-fields
CPT, but I'd not yet changed the Layout group.Text
field being displayed was from the cloned group. Its key was field_64abd97b8ff80_field_64aa869f48df7
TBC
The clone
field type allows the user to use fields that have already been defined in other Field groups.
From the documentation at https://www.advancedcustomfields.com/resources/clone/
The clone field allows you to select and display existing fields. It does not duplicate any fields in the DB, instead, it loads and displays the selected fields at run-time.
You may also select one (or more) field groups making it possible to load in ‘module’ groups. A good example of this can be seen with the screenshots below where a single field group is created for ‘Button’ information. This field group is then ‘cloned’ when a button is needed.
The clone field may be used in one of two ways.
The ACF field type group
is a field that consists of zero or more sub fields.
It's possible to nest groups within groups.
The Icon Picker was added in ACF 6.3. Current version of ACF is 6.3.2
Support display of icons that have been picked using the Icon Picker
I don't know what caused it but in the block editor there's no field name selected in the block editor
even though the front end display works.
This is probably due to the fact that I changed to logic to use the field key rather than field name but forgot to update the examples.
See #16
<!-- wp:acf-field/acf-field {"name":"acf-field/acf-field","data":{"acf-field-name":"password","_acf-field-name":"field_645f589a88304"},"mode":"edit"} /-->
<!-- wp:acf-field/acf-field {"name":"acf-field/acf-field","data":{"field_645f589a88304":"field_64aa874448e00"},"mode":"edit"} /-->
field-block-for-acf-pro is now available from wordpress.org/plugins/field-block-for-acf-pro.
It's the first version but I'm having problems with both ACF Pro and the block in s.b/cwiccer
ACF Pro version: 6.2.5
WordPress version: 6.4.1
PHP: 8.3
ACF Pro is only displaying one Field group, which is currently the Testimonials group, and it's associated with Posts
BUT when you edit a Post the other field groups are being displayed as well.
Note: When you hover over the Testimonials field group the settings icon is displayed.
It's not available for the other field groups.
The Display label field is not taking effect.
In s.b/cwiccer the HTML for the block is
Originally posted by @bobbingwide in bobbingwide/bobbingwide#95 (comment)
The flexible_content
field type is similar to the repeater
field type.
You need to define one or more layouts
in order for the Add Row button to display the layout type you want to add.
The field_info structure contains layouts
which is a multi-dimensional associative array of layout arrays which contain an array of sub_fields
within the layout.
When I create a new Page that's associated to my test Field Group "Testimonials" several unwanted things happen.
Q: Should I disable the acf-field block for the password
field type? or simply display stars?
Repeaters are similar to groups but support more than one instance of data.
Detected after cloning content from s.b/oikcom, the logic to render the checkbox field, which uses the rendering for select, doesn't produce the expected results.
We see the following Notice
Notice: Undefined index: a:1:{i:0;s:3:”red”;}
in /home/customer/www/oik-plugins.co.uk/public_html/wp-content/plugins/acf-field-block/includes/class-acf-field-block-renderer.php
on line 446
phpMyAdmin shows the values being stored as below.
meta_id post_id meta_key meta_value
393844 49098 checkbox a:1:{i:0;s:3:"red";}
393892 49098 select red
In actual fact, updating the field in the ACF metabox didn't appear to survive the round trip.
Several ACF field types would benefit from being able to select the Alignment; attribute align
.
This doesn't appear to work for "align": "center"
Setting | OK? |
---|---|
none | OK |
left | OK |
right | OK |
center | No |
It appears that for aligncenter
to work the block needs the class has-text-align-center
.
See oik_server_side_wrapper()
for example code, passing $extra_attributes
to get_block_wrapper_attributes()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.