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

Documentation showing reuse #23

Open
mindfullsilence opened this issue Jul 10, 2017 · 1 comment
Open

Documentation showing reuse #23

mindfullsilence opened this issue Jul 10, 2017 · 1 comment

Comments

@mindfullsilence
Copy link

All documentation examples show single-use case. Would be nice to see a page dedicated to showing how fields/complex fields can be reused. I feel like that's where the real power of this library is. Showing how to do it via functional programming like below as well as a class declaration I'm sure would be helpful to some:

    function getLinkGroup($name = 'link') {
        return Field::make( 'complex', $name )
            ->add_fields( array(
                Field::make( 'text', 'linktext'),
                Field::make( 'text', 'url'),
                Field::make( 'checkbox', 'newtab' ) )
            )
        );
    }

    function getImageGroup( $name = 'image' ) {
        return Field::make( 'complex', 'image' )
            ->add_fields( array(
                Field::make( 'image', 'mobile' ),
                Field::make( 'image', 'tablet' ),
                Field::make( 'image', 'desktop' ) )
            )
    }

    function getWysiwyg( $name = 'content' ) {
        return Field::make( 'rich_text', $name )
    }
    
    Container::make( 'post_meta', 'Author Info' )
        ->where( 'post_type', '=', 'post' )
        ->add_fields( array(
            getLinkGroup(),
            getImageGroup( 'avatar' ),
            getWysiwyg() )
        );
    
    Container::make( 'post_meta', 'Call To Action Button' )
        ->where( 'post_type', '=', 'page' )
        ->add_fields( array(
            getLinkGroup() )
        );
@BenBroide
Copy link

Very useful example, thanks @mindfullsilence . Iv'e send a pull request #30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants