Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  bump to 1.10.0
  Support row layout of cmb2 group
  Support table layout of cmb2 group
  Make tab styles more intuitive
  Remove docs about pull request which has been merged into my cmb2 fork
  Move Tab class to Box/Tabs
  add some phpdocs around using CMB2 tabs
  Support keyed and flat arrays with Class_Names
  support empty values and like queries
  • Loading branch information
lipemat committed Nov 13, 2018
2 parents c594f82 + 75b9130 commit 2314f64
Show file tree
Hide file tree
Showing 10 changed files with 484 additions and 70 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# WordPress Libs
WordPress library which supports a core plugin and theme.

**Version [1.9.1](https://github.com/lipemat/wordpress-lipe-libs/releases/tag/1.9.1)**
**Version [1.10.0](https://github.com/lipemat/wordpress-lipe-libs/releases/tag/1.10.0)**

### Requirements
1. PHP Version 7.1+ (Recommended 7.2+)
1. PHP Version 7.2
2. WordPress Version 4.8=<5.0 (Recommended 4.9=<5.0)


Expand All @@ -20,7 +20,7 @@ require __DIR__ . '/vendor/autoload.php'

### Current Features (non exhaustive)
* YouTube Api integration
* CMB2 mapping
* CMB2 mapping + group display formats
* Meta Data repository
* Custom Post Type registration object
* Extended CPTS mapping
Expand All @@ -45,6 +45,11 @@ require __DIR__ . '/vendor/autoload.php'
* Version management helper
* Comment Object Trait

### Changelog (non exhaustive)

#### 1.10.0
* Support using keyed and flat arrays at the same time with Class_Names
* Add support for table and row displays of CMB2 groups



Expand Down
12 changes: 6 additions & 6 deletions src/CMB2/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Lipe\Lib\CMB2;

use Lipe\Lib\CMB2\Field_Types\Tab;
use Lipe\Lib\CMB2\Box\Tabs;

/**
* Box
Expand Down Expand Up @@ -302,22 +302,22 @@ public function __construct( $id, array $object_types, $title, $context = 'norma
*/
public function add_tab( string $id, string $label ) : void {
$this->tabs[ $id ] = $label;
Tab::init_once();
Tabs::init_once();
}


/**
* Should the tabs display vertical or horizontal?
* Default is vertical when not calling this.
*
* @param string $layout - vertical, horizontal (default to horizontal)
* @param string $layout - vertical, horizontal
*
* @since 1.2.0
*
* @return void
*/
public function tabs_style( string $layout ) : void {
$this->tab_style = $layout ? 'classic' : 'default';
public function tabs_style( string $layout = 'horizontal' ) : void {
$this->tab_style = $layout;
}

/**
Expand All @@ -341,7 +341,7 @@ public function get_box() : \CMB2 {
protected function get_args() : array {
$args = [];
foreach ( get_object_vars( $this ) as $_var => $_value ) {
if ( $_var === 'cmb' || ! isset( $this->{$_var} ) || 'fields' === $_var ) {
if ( 'cmb' === $_var || ! isset( $this->{$_var} ) || 'fields' === $_var ) {
continue;
}
$args[ $_var ] = $this->{$_var};
Expand Down
63 changes: 38 additions & 25 deletions src/CMB2/Field_Types/Tab.php → src/CMB2/Box/Tabs.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
<?php

namespace Lipe\Lib\CMB2\Field_Types;
namespace Lipe\Lib\CMB2\Box;

use CMB2_Field;
use Lipe\Lib\CMB2\Field;
use Lipe\Lib\Traits\Singleton;
use Lipe\Lib\Util\Class_Names;

/**
* Support Tabs in meta boxes
*
* @usage Assign and array of tabs to a box when registering it
* via the Lipe\Lib\CMB2\Box::add_tab() method.
* Then use the Lipe\Lib\CMB2\Field::tab() method to assign each field to a particular tab.
* Every field a box has must be assigned to a tab or none will display.
*
*
* @author Mat Lipe
* @since 1.2.0
*
* @package Lipe\Lib\CMB2\Field_Types
*/
class Tab {
class Tabs {
use Singleton;

/**
Expand Down Expand Up @@ -72,14 +80,15 @@ public function opening_div( $cmb_id, $object_id, $object_type, $cmb ) {
$this->has_tabs = true;

$tab_style = $cmb->prop( 'tab_style' );
$class = 'cmb-tabs clearfix';
$classes = new Class_Names( [
'cmb-tabs',
'clearfix',
] );
$classes[ 'cmb-tabs-' . $tab_style ] = ( null !== $tab_style && 'vertical' !== $tab_style );

if ( null !== $tab_style && 'default' !== $tab_style ) {
$class .= ' cmb-tabs-' . $tab_style;
}
$this->styles();

echo '<div class="' . $class . '">';
echo '<div class="' . esc_attr( $classes ) . '">';

}

Expand Down Expand Up @@ -121,9 +130,9 @@ public function render_nav( $cmb_id, $object_id, $object_type, $cmb ) {

printf(
'<li class="%s" data-panel="%s"><a href="#"><span>%s</span></a></li>',
$class,
$key,
$label
esc_attr( $class ),
esc_attr( $key ),
esc_html( $label )
);
}

Expand All @@ -146,9 +155,13 @@ public function add_wrap_class( $classes ) {


/**
* Replaces the render_field callback for a field which as been
* assigned to a tab
*
* @param array $field_args
* @param CMB2_Field $field
*
* @param $field_args
* @param $field
* @see Field::tab()
*
* @return void
*/
Expand All @@ -160,7 +173,7 @@ public function render_field( $field_args, CMB2_Field $field ) : void {
$field->render_field_callback();
}
$output = ob_get_clean();
echo $this->capture_fields( $output, $field_args, $field );
echo $this->capture_fields( $output, $field_args ); //phpcs:ignore
}


Expand All @@ -183,8 +196,8 @@ public function show_panels( $cmb_id, $object_id, $object_type, $cmb ) : void {

foreach ( $this->fields_output as $tab => $fields ) {
$active_panel = $this->active_panel === $tab ? 'show' : '';
echo '<div class="' . $active_panel . ' cmb-tab-panel cmb2-metabox cmb-tab-panel-' . $tab . '">';
echo implode( '', $fields );
echo '<div class="' . esc_attr( $active_panel ) . ' cmb-tab-panel cmb2-metabox cmb-tab-panel-' . esc_attr( $tab ) . '">';
echo implode( '', $fields ); //phpcs:ignore
echo '</div>';
}

Expand All @@ -208,7 +221,7 @@ public function capture_fields( $output, $field_args ) : string {
}


protected function styles() {
protected function styles() : void {
static $displayed = false;
if ( $displayed ) {
return;
Expand Down Expand Up @@ -445,9 +458,9 @@ protected function styles() {
}

/*--------------------------------------------------------------
Classic Tab
Horizontal Tabs
--------------------------------------------------------------*/
.cmb-tabs.cmb-tabs-classic ul.cmb-tab-nav {
.cmb-tabs.cmb-tabs-horizontal ul.cmb-tab-nav {
width: 100%;
float: none;
background-color: #fafafa;
Expand All @@ -457,37 +470,37 @@ protected function styles() {
padding-top: 15px;
}

.cmb-tabs.cmb-tabs-classic .cmb-tab-nav li {
.cmb-tabs.cmb-tabs-horizontal .cmb-tab-nav li {
background: #ebebeb none repeat scroll 0 0;
margin: 0 5px -1px 5px;
display: inline-block;
}

.cmb-tabs.cmb-tabs-classic .cmb-tab-nav li:first-of-type {
.cmb-tabs.cmb-tabs-horizontal .cmb-tab-nav li:first-of-type {
margin-left: 18px;
}

.cmb-tabs.cmb-tabs-classic ul.cmb-tab-nav::after {
.cmb-tabs.cmb-tabs-horizontal ul.cmb-tab-nav::after {
display: none;
}

.cmb-tabs.cmb-tabs-classic .cmb-tabs-panel {
.cmb-tabs.cmb-tabs-horizontal .cmb-tabs-panel {
width: 100%;
}

.cmb-tabs.cmb-tabs-classic .cmb-tab-panel {
.cmb-tabs.cmb-tabs-horizontal .cmb-tab-panel {
/*background: #ebebeb none repeat scroll 0 0;*/
padding-top: 10px;
}

.cmb-tabs.cmb-tabs-classic ul.cmb-tab-nav li a {
.cmb-tabs.cmb-tabs-horizontal ul.cmb-tab-nav li a {
padding: 8px 12px;
background-color: #fafafa;
border: none;
border-bottom: 1px solid #dedede;
}

.cmb-tabs.cmb-tabs-classic ul.cmb-tab-nav li.cmb-tab-active a {
.cmb-tabs.cmb-tabs-horizontal ul.cmb-tab-nav li.cmb-tab-active a {
background-color: #fff;
border-color: #fff;
border: none;
Expand Down
9 changes: 5 additions & 4 deletions src/CMB2/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Lipe\Lib\CMB2;

use Lipe\Lib\CMB2\Field_Types\Tab;
use Lipe\Lib\CMB2\Box\Tabs;

/**
* Field
Expand Down Expand Up @@ -698,16 +698,17 @@ public function query_args( array $args ) : Field {
* The tab must be first registered with the box.
*
* @see \Lipe\Lib\CMB2\Box::add_tab()
* @see Tabs::render_field()
*
* @param string $id
*
* @return $this
*/
public function tab( string $id ) {
Tab::init_once();
public function tab( string $id ) : Field {
Tabs::init_once();

$this->tab = $id;
$this->render_row_cb = [ Tab::in(), 'render_field' ];
$this->render_row_cb = [ Tabs::in(), 'render_field' ];

return $this;
}
Expand Down
Loading

0 comments on commit 2314f64

Please sign in to comment.