PHP code example of wieni / wmmodel_factory

1. Go to this page and download the library: Download wieni/wmmodel_factory 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/ */

    

wieni / wmmodel_factory example snippets




namespace Drupal\your_module\Entity\ModelFactory\Factory\Node;

use Drupal\your_module\Entity\Meta\Meta;
use Drupal\wmmodel_factory\EntityFactoryBase;

/**
 * @EntityFactory(
 *     entity_type = "node",
 *     bundle = "page"
 * )
 */
class PageFactory extends EntityFactoryBase
{
    public function make(): array
    {
        return [
            'title' => $this->faker->sentence(4),
            'menu_link' => null,
            'field_meta' => [
                'entity' => $this->faker->entity(Meta::class),
            ],
            'field_intro' => $this->faker->optional()->text(320),
        ];
    }
}



namespace Drupal\your_module\Entity\ModelFactory\State\Node;

use Drupal\wmmodel_factory\EntityStateBase;

/**
 * @EntityState(
 *     name = "unpublished",
 *     entity_type = "node",
 * )
 */
class UnpublishedState extends EntityStateBase
{
    public function make(): array
    {
        return [
            'status' => 0,
        ];
    }
}