PHP code example of amazeelabs / silverback_gutenberg
1. Go to this page and download the library: Download amazeelabs/silverback_gutenberg library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
amazeelabs / silverback_gutenberg example snippets
namespace Drupal\custom_gutenberg\Plugin\Validation\GutenbergValidator;
use Drupal\silverback_gutenberg\GutenbergValidation\GutenbergValidatorBase;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* @GutenbergValidator(
* id="my_block_validator",
* label = @Translation("My block validator")
* )
*/
class MyBlockValidator extends GutenbergValidatorBase {
use StringTranslationTrait;
/**
* {@inheritDoc}
*/
public function applies(array $block) {
return $block['blockName'] === 'custom/my-block';
}
/**
* {@inheritDoc}
*/
public function validatedFields(array $block = []) {
return [
'email' => [
'field_label' => $this->t('Email'),
'rules' => ['
namespace Drupal\silverback_gutenberg\Plugin\GutenbergBlockMutator;
use Drupal\silverback_gutenberg\Attribute\GutenbergBlockMutator;
use Drupal\silverback_gutenberg\BlockMutator\EntityBlockMutatorBase;
use Drupal\Core\StringTranslation\TranslatableMarkup;
#[GutenbergBlockMutator(
id: "media_block_mutator",
label: new TranslatableMarkup("Media IDs to UUIDs and viceversa."),
)]
class MediaBlockMutator extends EntityBlockMutatorBase {
/**
* {@inheritDoc}
*/
public bool $isMultiple = TRUE;
/**
* {@inheritDoc}
*/
public string $gutenbergAttribute = 'mediaEntityIds';
/**
* {@inheritDoc}
*/
public string $entityTypeId = 'media';
}
namespace Drupal\silverback_gutenberg\Plugin\GutenbergBlockMutator;
use Drupal\silverback_gutenberg\Attribute\GutenbergBlockMutator;
use Drupal\silverback_gutenberg\BlockMutator\EntityBlockMutatorBase;
use Drupal\Core\StringTranslation\TranslatableMarkup;
#[GutenbergBlockMutator(
id: "node_block_mutator",
label: new TranslatableMarkup("Node ID to UUID and viceversa."),
)]
class NodeBlockMutator extends EntityBlockMutatorBase {
/**
* {@inheritDoc}
*/
public string $gutenbergAttribute = 'nodeId';
/**
* {@inheritDoc}
*/
public string $entityTypeId = 'node';
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.