esign/craft-cms-crud 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

esign/craft-cms-crud

Composer 安装命令:

composer require esign/craft-cms-crud

包简介

This module contains the basic CRUD programmatically functions for Craft CMS

README 文档

README

This module contains the basic CRUD functions for Craft CMS

Installation

You can install the package via composer, and Craft to install it:

composer require esign/craft-cms-crud && php craft plugin/install craft-cms-crud 

Usage

updateOrCreateEntry

Currently there is only one function and that is updateOrCreateEntry, this can update an entry with all his fields (fields, matrix blocks & nested entries)

$entry has to be an instance of esign\craftcmscrud\support\CraftEntry then we are sure all fields can be mapped right

use esign\craftcmscrud\controllers\CraftEntryController;

class YourController extends CraftEntryController
{
    CraftEntryController::updateOrCreateEntry($entry);
}

Entry Objects

CraftEntry.php

use esign\craftcmscrud\support\CraftEntry;

new CraftEntry(
    $handle, 
    $identifier, 
    $fields, 
    $matrixBlocks, 
    $nestedEntries
)

$handle -> expects your section handle name

$identifier -> expects your identifier for that entry (used for updating an entry instead of creating one)

$fields -> expects a stdClass of your entry fields (including title & slug) OR an array of stdClasses of your entry fields (this is used for nested entries more on this later)

$matrixBlocks -> expects an array of CraftMatrixBlock classes (see section CraftMatrixBlock)

$nestedEntries -> expects an array of CraftEntry classes

CraftMatrixBlock.php

use esign\craftcmscrud\support\CraftMatrixBlock;

new CraftMatrixBlock(
    $handle, 
    $handleBlock, 
    $fields
)

$handle -> expects your field handle name

$handleBlock -> expects your matrix block handle name

$fields -> expects an array of stdClasses of your matrix fields

CraftAsset.php

use esign\craftcmscrud\support\CraftAsset;

new CraftAsset(
    $handle,
    $imageUrl,
    $filename,
    $path,
)

$handle -> expects your field handle name

$imageUrl -> expects your external image url

$filename -> expects filename

$path -> expects the path of your asset field

Example

use esign\craftcmscrud\controllers\CraftEntryController;
use esign\craftcmscrud\support\CraftEntry;
use esign\craftcmscrud\support\CraftMatrixBlock;

CraftEntryController::updateOrCreateEntry(
    new CraftEntry(
        self::HANDLE_CLUB,
        self::IDENTIFIER_CLUB,
        ClubModel::fieldsFromClub($club),
        [
            new CraftMatrixBlock(
                self::HANDLE_OPENING_HOURS,
                self::HANDLE_OPENING_HOURS_BLOCK,
                $club->{self::HANDLE_OPENING_HOURS}
            ),
            ...
        ],
        [
            new CraftEntry(
                self::HANDLE_CLUB_TAGS,
                self::IDENTIFIER_CLUB_TAGS,
                ClubModel::collectionFieldsFromClubTags($club->{self::HANDLE_CLUB_TAGS})
            ),
            ...
        ],
        [
            new CraftAsset(
                self::HANDLE_IMAGE,
                $contract->mlContractImageUrl,
                StringHelper::beforeFirst(StringHelper::afterLast($contract->mlContractImageUrl, '/'), '?'),
                self::HANDLE_IMAGE_PATH
            )
        ],
    ),
);

parseNestedMatrixBlocks

use esign\craftcmscrud\controllers\CraftEntryController;
use esign\craftcmscrud\support\CraftEntry;
use esign\craftcmscrud\support\CraftMatrixBlock;

public const MATRIX_BLOCKS_CONTRACT_TERM = [
    'mlTermPriceAdjustmentRules' => 'mlPriceBlock',
    'mlTermFlatFees' => 'mlFeeBlock',
    'mlTermOptionalModules' => 'mlOptionalBlock',
    'mlTermRateBonusPeriods' => 'mlBonusBlock',
];

CraftEntryController::updateOrCreateEntry(
    new CraftEntry(
        self::HANDLE_CONTRACT,
        self::IDENTIFIER_CONTRACT,
        Entry::fieldsFromContract($contract),
        null,
        [
            new CraftEntry(
                self::HANDLE_CONTRACT_TERM,
                self::IDENTIFIER_CONTRACT_TERM,
                Entry::collectionFieldsFromContractTerms(
                    $contract->{self::HANDLE_CONTRACT_TERM}
                ),
                CraftEntryController::parseNestedMatrixBlocks(
                    $contract->{self::HANDLE_CONTRACT_TERM},
                    self::MATRIX_BLOCKS_CONTRACT_TERM
                ),
            ),
        ],
    ),
);

CraftEntryController::parseNestedMatrixBlocks() is used to parse the nested matrix blocks.

MATRIX_BLOCKS_CONTRACT_TERM is the $sectionHandle => $blockHandle

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固