Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small PHP adjustments in Chisel methods #415

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions generators/app/templates/gulp/templatesFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ module.exports = function templateFunctions(data = {}) {
}
const classes = [name];
let el;
for (let i = 0; i < args.length; i += 1) {
el = args[i];
let modifiers;
if(args[0] instanceof Array) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JakubSzajna just a missing space after if

modifiers = args[0];
} else {
modifiers = args;
}
for (let i = 0; i < modifiers.length; i += 1) {
el = modifiers[i];
if (el && typeof el === 'string') {
classes.push(`${name}--${el}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ public function className( $name = '', $modifiers = null ) {
if ( ! is_string( $name ) || empty( $name ) ) {
return '';
}
$modifiers = array_slice( func_get_args(), 1 );
if ( ! is_array( $modifiers ) ) {
$modifiers = array_slice( func_get_args(), 1 );
}
$classes = array( $name );
foreach ( $modifiers as $modifier ) {
if ( is_string( $modifier ) && ! empty( $modifier ) ) {
Expand Down
35 changes: 32 additions & 3 deletions generators/wp/templates/chisel-starter-theme/Chisel/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,19 @@ protected function prepareFakePost( $fields ) {
* Overrides get_field function to use fake meta when provided.
*
* @param $field_name
* @param $default_value mixed Default value if field is empty
*
* @return mixed
*/
public function get_field( $field_name ) {
public function get_field( $field_name, $default_value = null ) {
$value = null;
if ( $this->fakeFields && isset( $this->fakeFields[ $field_name ] ) ) {
return $this->fakeFields[ $field_name ];
$value = $this->fakeFields[ $field_name ];
} else {
$value = $this->_get_field( $field_name );
}

return parent::get_field( $field_name );
return $value ? $value : $default_value;
}

/**
Expand All @@ -69,4 +73,29 @@ public function get_field( $field_name ) {
public static function overrideTimberPostClass() {
return '\Chisel\Post';
}

/**
* @param string $field_name
*
* @return mixed
*/
private function _get_field( $field_name ) {
if ( $rd = $this->get_revised_data_from_method( 'get_field', $field_name ) ) {
return $rd;
}
$value = apply_filters( 'timber_post_get_meta_field_pre', null, $this->ID, $field_name, $this );
if ( $value === null ) {
$value = get_post_meta( $this->ID, $field_name );
if ( is_array( $value ) && count( $value ) == 1 ) {
$value = $value[0];
}
if ( is_array( $value ) && count( $value ) == 0 ) {
$value = null;
}
}
$value = apply_filters( 'timber_post_get_meta_field', $value, $this->ID, $field_name, $this );
$value = $this->convert( $value, get_class( $this ) );

return $value;
}
}