承接 arnaudbagnis/acf-gutenberg-custom-block 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

arnaudbagnis/acf-gutenberg-custom-block

Composer 安装命令:

composer require arnaudbagnis/acf-gutenberg-custom-block

包简介

Acf Gutenberg custom Block for Lumberjack Framework

README 文档

README

This package provides a custom block creation functionality for the Lumberjack theme with the help of ACF Pro plugin. It includes a Provider and an AbstractBlock class that allows you to create custom blocks quickly and easily.

Installation

To use this package, you need to have ACF Pro installed and activated in your project. You can install this package via composer by running the following command:

composer require arnaudbagnis/acf-gutenberg-custom-block

Usage

Create a new block in your theme's block directory by extending the AbstractBlock class provided by this package. Here is an example:

<?php
namespace App\Guttenberg\Block;

use Timber\Timber;

class MyCustomBlock extends AbstractBlock
{

    public static function getName(): string
    {
        return "my-custom-block";
    }

    public static function getTitle(): string
    {
        return "My Custom Block";
    }

    public static function getDescription(): string
    {
        return "This is a description";
    }

    public static function getCategory(): string
    {
        return "formatting";
    }

    public static function getIcon(): string
    {
        return "admin-comments";
    }

    public static function getKeywords(): array
    {
        return array('my-custom-block', 'quote');
    }

    public static function getExample(): array
    {
        return array();
    }

    public static function getEnqueueAssets()
    {
        // Add a style/js for only this block
        return null;
    }

    public static function getLocalFieldGroup(): array
    {
        // Add a php field acf block for stay in memories
        return [];
    }

    public static function getController($block)
    {
        $context = Timber::context();
        // retrieve an ACF field here
        $context['settings'] = [
            'title' => get_field('title'),
            'description' => get_field('description'),
            'image_right' => get_field('image_right'),
            'cta' => get_field('cta'),
            'explanations' => get_field('explanations'),
        ];
        Timber::render('templates/blocks/' . static::getName() . '.twig', $context);
    }
}

Create a block.php file in your theme's config directory and add the following code to it:

<?php

use App\Guttenberg\Block\MyCustomBlock;

return [
    'styles' => [
        './assets/dist/main.css'
    ],
    'blocks' => [
        MyCustomBlock::class,
    ]
];

The styles array allows you to add global styles to the Gutenberg editor, while the blocks array allows you to add the blocks you created.

That's it! Your custom block is now ready to be used in the Gutenberg editor.

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: mit
  • 更新时间: 2023-03-13