pinkcrab/admin-pages

此包已被 废弃 且不再维护。作者建议使用 pinkcrab/perique-admin-menu 包。

PinkCrab 框架包,用于通过继承插件和主题非常容易地创建管理页面/组。

0.1.2 2021-04-13 01:33 UTC

This package is auto-updated.

Last update: 2021-08-06 23:08:04 UTC


README

PinkCrab 框架包,用于通过继承插件和主题非常容易地创建管理页面/组。

alt text Open Source Love codecov

有关更多详细信息,请访问我们的文档。 https://app.gitbook.com/@glynn-quelch/s/pinkcrab/

版本

发布 0.1.2

为什么?

创建许多 WordPress 的内部固定项有时可能非常冗长,使用大数组值,如果值不正确不会抛出错误。

PinkCrab Registerables 模块提供了一些可以扩展并添加到注册系统中的抽象类。

依赖

  • 需要 PinkCrab 框架 V0.3 及以上版本。

安装

$ composer require pinkcrab/admin-pages

示例

<?php
class Single_Menu_Page extends Menu_Page_Group {

	// Define menu details
	public $key        = 'simple_single_page';
	public $menu_title = 'Single Page';
	public $icon_url   = 'dashicons-image-filter';

	// Define page details
	public function set_parent_page( Page $page ): Page {
		return $page
			->title( 'Single Page Title' )
			->view_template( 'admin/page/page-single' )
			->view_data( $this->page_contents() );
	}
	
	// Returns the data for the view.
	protected function page_contents(): array{
		return ['whatever' => 'is needed for your template'];
}
use PinkCrab\Admin_Pages\Page;
use PinkCrab\Core\Application\App;
use My_Plugin\Something\My_Service;
use PinkCrab\Admin_Pages\Page_Validator;
use PinkCrab\Core\Interfaces\Renderable;
use My_Plugin\Something\My_Other_Service;
use PinkCrab\Admin_Pages\Menu_Page_Group;
use PinkCrab\Admin_Pages\Page_Collection;

class My_Admin_Group extends Menu_Page_Group {

	public $key        = 'my_admin_group';
	public $menu_title = 'Admin Group';

	/**
	 * Creats an instance of a Menu_Page_Group injected with our
	 * needed additional dependencies.
	 *
	 * The intial $app must be passed to the parent constructor.
	 *
	 * @param \My_Plugin\Something\My_Service $my_service
	 * @param \My_Plugin\Something\My_Other_Service $my_other_service
	 * @param \PinkCrab\Core\Application\App $app
	 */
	public function __construct(
		My_Service $my_service,
		My_Other_Service $my_other_service,
		App $app
	) {
		// Ensure parent constructor is populated and ran as expected!
		parent::__construct( $app );

		$this->my_service       = $my_service;
		$this->my_other_service = $my_other_service;
	}

	/**
	 * Register the parent/main page.
	 *
	 * @param Page $page
	 * @return Page $page
	 */
	public function set_parent_page( Page $page ): Page {
		return $page
			->title( 'Inital Page for the group title' )
			->view_template( 'admin/page/page-index' )
			->view_data( $this->my_other_service->page_two_data() );
	}

	/**
	 * Register all child pages.
	 *
	 * @param Page_Collection $children
	 * @return Page_Collection
	 */
	public function set_child_pages( Page_Collection $children ): Page_Collection {

		// Populate from a seperate method, returns the populated page.
		$children->add( $this->child_page_one() );

		// Using the factory method in the Child Page Collection, 
		$children->add_child_page(
			function( Page_Factory $factory ): page {
				return $factory->child_page( 'Page Two', 'page_2' )
					->title( 'Page Title for Page Two' )
					->view_template( 'admin/page/page-two' )
					->view_data( $this->my_other_service->page_two_data() );
			}
		);


		return $children;
	}

	/**
	 * Holds the configuration for our child page.
	 *
	 * @return Page
	 */
	public function child_page_one(): Page {
		
		// Create the page using the static constructor for a Page
		// Arguments = age key/slug, menu title & parent key/slug
		$page = Page::create_page( 'page_one', 'Page One', $this->key );		

		$page->title( 'Page Title for Page One' );
		$page->position( 3 ); // Show last

		// Set the view details
		$page->view_template( 'admin/page/page-one' );
		$page->view_data(
			array(
				'header'   => $this->my_service->pages->header,
				'sections' => $this->my_service->pages->get_sections( 'page_one' ),
				'footer'   => $this->my_service->pages->footer,
				'user'     => \get_current_user(),
			)
		);

		return $page;
	}
}

可渲染

所有页面模板都使用当前设置的任何 Renderable 实现。

测试

运行完整套件(如通过 GH CLI 运行)

	composer all

PHP 单元测试

如果您想为此包运行测试,请在运行 phpunit 之前确保将您的数据库详细信息添加到 test/wp-config.php 文件中。

$ composer test

带有覆盖率报告运行

$ composer coverage

PHP Stan

该模块包含所有 WP 函数的 polyfill,允许测试所有核心文件。当前配置省略了 Dice 文件,因为这个文件不属于我们。要运行套件,请调用。

$ vendor/bin/phpstan analyse src/ -l8 
$ composer analyse

PHPCS

您可以通过调用运行代码库的 PHPCS。

$ composer sniff

许可

MIT 许可证

https://open-source.org.cn/licenses/mit-license.html

变更日志

  • 0.1.2 - 添加了缺失的 ACF 测试和字段。
  • 0.1.1 - 更改了 Loader 的命名空间并连接了 GitHuc CLI
  • 0.1.0 - 移至 composer。