folbert / fewbricks Goto Github PK
View Code? Open in Web Editor NEWWrite code to create ACF field groups, fields and re-usable modules.
Home Page: https://fewbricks2.folbert.com
License: GNU General Public License v3.0
Write code to create ACF field groups, fields and re-usable modules.
Home Page: https://fewbricks2.folbert.com
License: GNU General Public License v3.0
Create a file that holds the basic code for a brick. Reference that file from the readme file instead of putting the boilerplate code there.
Well this nearly killed me.
ACF would not display Fewbricks groups in admin, until (after a VERY LONG time), I worked out it ignores groups where the key doesn't begin with "group_".
This is an easy fix, adding this line to the top of the __contruct() of \fewbricks\acf\field_group class.
$key = (strpos($key, 'group_') === 0) ? $key : "group_$key";
A
Related to: #38
Can't seem to make the labels top aligned or change the width of the fields...
Thoughts?
Remove returning $this from setter methods. This is to remove the possibilities of chaining which I feel is not the way to go. It makes the code using the functions harder to read IMHO.
Test if automatically creating/reading PHP code is really worth it. It should be but let's try to find out just how much load time can be saved using it.
Feature to test implemented in 4beef2f
The instructions say "You should now, instead of the standard WYSIWYG area, see a bunch of fields and buttons that looks like the standard ACF GUI. That is actually what it is with the exception that they have been put there using Febwricks. Head on over to [theme]/fewbricks/field-groups/init.php to start tracking what is going on and how everything works."
However, I'm still seeing the normal wysiwyg area. I've triple checked that I installed it per your instructions. My copy of "template-fewbricks-demo.php" resides in the root if matters, and the new page created was set to use that template.
Any ideas what I'm missing here? Was there a step where .json data is supposed to be imported or some such? Scratching my head at what I did wrong.
Thank,
Mark
Would in turn add possibility to create field groups based on an existing field group.
Related to #21 so we'll make sure to merge that pull request in as well.
Hi @folbert , me again.
See https://github.com/folbert/fewbricks/blob/master/lib/acf/layout.php#L111
Since that function is protected
, I am unable to call common fields as sub fields. If I switch it to public
, it works like a charm. Can I open a PR with these changes?
Copied question by @christianmagill from issue nr 1 to avoid mixing issues.
_
Would it be possible to add Composer support for Bricks and Layouts as well?
It would be cool to be able to choose in composer which items you need for your particular project.
Hi,
I'm not aware of how exactly, ACF are changing the way fields are built and handled once Gutenberg is merged into core but, i'm sure there will be many changes over the next year.
When building Fewbricks V2, are these changes plus Gutenberg itself and what it means for the future of common place WordPress development being considered?
Me again.
In \fewbricks\acf\field_groups class, I've replaced
register_field_group($this->settings);
with
if( function_exists('acf_add_local_field_group') ) {
add_action('acf/init', function() {
acf_add_local_field_group($this->settings);
});
}
This is the prescribed way in ACF5 and it ensured registration must happen at the right time.
I also think this action, in the plugin root file, is then probably not needed (i.e. just run the construct() immediately):
add_action('after_setup_theme', function() {
fewbricks\fewbricks::construct();
});
A
cred to @frebro for this idea.
...also change the name "common field groups" to something that does not make you believe it has something to do with ACFs field groups.
This was inspired by https://github.com/devgeniem/acf-codifier#creating-fields
hello
wanted to give fewbricks a run but I'm running into two issues:
what am I missing?
thanks
To make it possible to do something like
$text_field = (new Select())
->setRequired(true)
->setChoices(
[
'option1' => 'Option 1',
'option2' => 'Option 2'
]
);
This will allow bricks to find out if they are being used inside a specific brick and for example run some code only needed if a specific layout is used.
First, this codebase is absolute amazing. I pulled up the demo and BAM...just works.
Noticed you were using your own spl loader for the [theme]/fewbricks/[file] loading. If this is already a composer package, why not use composer's autoloader?
Same way that developer mode or use ACF JSON is set.
Describe get_brick_template_html() in the readme file
Have it handle second level arrays so you can pass
[
'style' => [
'color' => 'red',
'font-size' => '2rem',
],
'class' => [
'a-class another-class',
'a-third-class',
]
]
Add code for hiding the default content-editor in the field group for the demo template.
Hiya Folbert. I've just discovered this and it looks awesome.
Just noticed that you've not updated yet to accommodate the ACF Clone field.
What are your thoughts there?
Cheers
A
Doesn't seem like there's a way to pass settings other than fields when calling add_brick
: https://github.com/folbert/fewbricks/blob/master/lib/brick.php#L216
Let me know if I'm missing something, otherwise I'll get to work on a PR.
Either cast a WP Error or fail quietly.
Note to self: See project_brick for Boilerplate project.
Maybe even be able to group attributes in case you have multiple elements in your layouts and want to set different attributes on those elements.
/**
* $append = true if value should be appended to existing value of attribute
*/
set_attribute($name, $value, $group_name = false) {
}
/**
* Special function for styles since values should have ';' to separate values.
*/
add_style($attribute, $value, $group_name = false) {
$attr['style'] .= $attribute . ':' . $value . ';'
}
clear_attribute($name, $group_name = false) {
}
Just like field keys but for names.
For example for field Select
public function setChoices($choices) {
$this->setSettings('choices', $choices);
}
This will allow for writing
$data = $this->get_field_values(['field_name', 'another_field_name]);
instead of
$data['field_name'] = $this->get_field('field_name');
$data['another_field_name'] = $this->get_field('another_field_name');
Code:
/**
* @param $field_names
* @return array
*/
protected function get_field_values($field_names)
{
$values = [];
foreach($field_names AS $field_name) {
$values[$field_name] = $this->get_field($field_name);
}
return $values;
}
/**
* @param array $field_names ['field_name_1', 'field_name_2', ['field_name_3' => 'name_to_save_as']]
* @return array
*/
protected function get_field_values_from_options($field_names)
{
$values = [];
foreach($field_names AS $field_name) {
if(is_array($field_name)) {
$key = key($field_name);
$values[$field_name[$key]] = get_field($key, 'options');
} else {
$values[$field_name] = get_field($field_name, 'options');
}
}
return $values;
}
This was inspired by https://github.com/devgeniem/acf-codifier#creating-a-field-group
Make bricks and layouts support Timber.
Please add a filter in brick::get_brick_template_html() to override the default base directory for template files in the theme directory, like
$template_base_path = apply_filters('fewbricks/brick/template_base_path', get_stylesheet_directory() . '/fewbricks/bricks/');
$template_path = $template_base_path .
str_replace('_', '-', \fewbricks\helpers\get_real_class_name($this)) .
'.template.php';
If possible. Considering that some fields saves default values etc. it may not be possible to write a generic function for this.
Any plans to add composer support to this? Would be awesome!
In short, an update from Fewbricks 1.X to v2 will not be possible without rewriting some/most/all code that is using Fewbricks.
The plan is to rewrite core to adhere to PSR-2 when it comes to class names etc. I will probably also do a complete overhaul on how field groups, fields etc. are registered "under the hood" and the API to communicate with Fewbricks. All existing functionality will be kept and some new functionality will be added. During the years since i created the first, unpublished, version of Fewbricks and up to now, I have learnt a lot about ACF, WP and PHP in general so I will try to apply that to v2.
Please note that there is absolutely no ETA for a release of any kind. But do feel welcome to make feature requests.
Like done in EchoCrate.
By giving each brick its own publish-status, admins could add new bricks and setting them statuses such as "draft" or "unpublished" or, by default, "published".
Let's try to find a way to add helper functions to accommodate easy implementation of such a feature on brick level.
Off the top of my head:
new bricks\main_content_1('main_content_1', '1607050854_b', [new acf_fields\text([....])])
Hi @folbert ! Great work, this is awesome stuff.
I am running into a slight issue, which is that there seems to be no way to "terminate" a Repeater within a Flexible Content field.
See screenshot: http://jmp.sh/AlEg9Wf
The last three tabs there are actually supposed to be part of the next Layout. But since the code is just add_sub_field
over and over, it appears to just tack them on to the Repeater:
# =============================================================================>
# 5. 25/75 Image and Text
# =============================================================================>
$l = new layout( '5. 25/75 Image and Text', 'image_text_25_75', '201704051323a' );
// Content tab
$l->add_sub_field(
new acf_fields\tab(
'Content', '', '201704051323b', [
'placement' => 'top',
'endpoint' => 0,
]
)
);
$repeater = (
new acf_fields\repeater(
'25/75 Image and Text', 'image_text_25_75_row', '201704051335a', [
'min' => 1,
'max' => 6,
'layout' => 'block',
'button_label' => 'Add Row',
]
)
);
$repeater->add_sub_field(
new acf_fields\radio(
'Image Position', 'image_position', '201704051341a', [
'wrapper' => [
'width' => '50'
],
'choices' => [
'left' => 'Left',
'right' => 'Right',
],
'layout' => 'horizontal',
'return_format' => 'value'
]
)
);
$l->add_sub_field( $repeater );
// Styles tab
$l->add_sub_field(
new acf_fields\tab(
'Styles', '', '201704051353a', [
'placement' => 'top',
'endpoint' => 0,
]
)
);
$l->add_brick( new colors( 'colors', '201704051253b' ) );
$fc->add_layout( $l );
# =============================================================================>
# 7. 50/50 Text
# =============================================================================>
$l = new layout( '7. 50/50 Text', 'text_50_50', '201704051323a' );
$l->add_sub_field(
new acf_fields\radio(
'Headline Format', 'headline_format', '201704051355a', [
'instructions' => '<span style="font-size:11px; font-style:italic;">If single headline, headline will be centered over both columns. If two headlines, each headline will be aligned left over their respective columns.</span>',
'choices' => array (
'one' => 'Single',
'two' => 'Double',
),
'default_value' => 'one : Single',
'layout' => 'vertical',
'return_format' => 'value',
]
)
);
// Left Side tab
$l->add_sub_field(
new acf_fields\tab(
'Left Side', '', '201704051428a', [
'placement' => 'top',
'endpoint' => 0,
]
)
);
$l->add_sub_field(
new acf_fields\text(
'Left Headline', 'left_headline', '201704051432a', [
'conditional_logic' => array (
array (
array (
'field' => '201704051355a',
'operator' => '==',
'value' => 'two',
),
),
),
]
)
);
$l->add_sub_field(
new acf_fields\wysiwyg(
'Left Content', 'left_content', '201704051434a'
)
);
// Right Side tab
$l->add_sub_field(
new acf_fields\tab(
'Right Side', '', '201704051435a', [
'placement' => 'top',
'endpoint' => 0,
]
)
);
$l->add_sub_field(
new acf_fields\text(
'Right Headline', 'right_headline', '201704051435b', [
'conditional_logic' => array (
array (
array (
'field' => '201704051355a',
'operator' => '==',
'value' => 'two',
),
),
),
]
)
);
$l->add_sub_field(
new acf_fields\wysiwyg(
'Right Content', 'right_content', '201704051435c'
)
);
// Styles tab
$l->add_sub_field(
new acf_fields\tab(
'Styles', '', '201704051436a', [
'placement' => 'top',
'endpoint' => 0,
]
)
);
$l->add_brick( new colors( 'colors', '201704051441b' ) );
$fc->add_layout( $l );
Note: When adding the Repeater to the Layout, I have tried both add_sub_field
and add_repeater
, and both produce the same result.
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.