定制 wp63/acf-block-loader 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wp63/acf-block-loader

最新稳定版本:v1.3.0

Composer 安装命令:

composer require wp63/acf-block-loader

包简介

Wrapper class for easy ACF Gutenberg Block registration

README 文档

README

Wrapper class for easy ACF Gutenberg Block registration

Install

composer require wp63/acf-block-loader

Usage

By default, Class file are to be stored inside Blocks directory in theme root directory (or app\Blocks in Sage 9). File name should be the same as Classname as in PSR-4.

  1. Create a class extending WP63\Block
  2. Class default namespace is WP63\Blocks\
  3. Class must have at least 2 methods: register() and static render()
<?php
namespace App\Blocks;

use WP63\Block;

class MyBlock extends Block {
  protected function register() {
    return [
      'name' => $name,
      'title' => $title,
      'category' => $category,
      'fields' => $fields,
    ];
  }

  public static function render( $options ) {
    // You can directly render HTML within `render()` method
    ...
    display block html
    ...

    // Or alternatively, return an array for Blade template engine in Sage 9
    return [
      'name' => 'value', // $name in template file
      'foo' => 'bar', // $foo in template file
    ];
  }
}

register() method will return an array with 3 keys

  • $name block-unique-name
  • $title Block Title
  • $category Block category. Predefined categories are [ common | formatting | layout | widgets | embed ] (Optional)
  • $fields ACF fields StoutLogic\AcfBuilder\FieldsBuilder object. Output of FieldsBuilder::build() method.

render() is the static method for rendering actual block. Every output generated inside this method will be part of block html. Render method will have access to 4 callback arguments from ACF via $options arguments

  • array $options->block The block settings and attributes.
  • string $options->content The block inner HTML (empty).
  • boolean $options->is_preview True during AJAX preview.
  • int|string $options->post_id The post ID this block is saved to.

Filters

  • wp63/acf_block_namespace Change block namespace. Default: App\Blocks\
  • wp63/acf_block_directory Change directory name. Default: ./Blocks
  • wp63/acf_block_template_directory Change Blade template directory. relative to /views directory Default: blocks

Actions

  • wp63/before_block_render Before each block is rendered
  • wp63/before_block_render/{$block_name} Before $block_name is rendered
  • wp63/after_block_render After each block is rendered
  • wp63/after_block_render/{$block_name} After $block_name is rendered

Use with Blade template engine in Sage 9

  1. In class render() method, instead of echo output directly, return an array contains all data to be exposed to Blade template file.
  2. Create template file in views/blocks the file name must be the same as block nam3 ($name). for example: views/blocks/hero-banner.blade.php

统计信息

  • 总下载量: 7.96k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2019-06-19