Skip to content
Permalink
Browse files

[generate:entity:content] Added owner option (#4098)

* [update:execute] Fixed update table

* Revert "Merge remote-tracking branch 'upstream/master'"

This reverts commit ddf7739, reversing
changes made to a95b7e6.

* [generate:entity:content] Added owner option
  • Loading branch information...
harold20 authored and enzolutions committed Jun 22, 2019
1 parent 02498e8 commit 6fb60046c50b4514fc4b7a723010b3271e42e779
@@ -102,8 +102,14 @@ protected function configure()
null,
InputOption::VALUE_NONE,
$this->trans('commands.generate.entity.content.options.has-forms')
)
->setAliases(['geco']);
);
$this->addOption(
'has-owner',
null,
InputOption::VALUE_NONE,
$this->trans('commands.generate.entity.content.options.has-owner')
)->setAliases(['geco']);
}
/**
@@ -143,6 +149,13 @@ protected function interact(InputInterface $input, OutputInterface $output)
true
);
$input->setOption('has-forms', $has_forms);
// --has-owner option
$has_owner = $this->getIo()->confirm(
$this->trans('commands.generate.entity.content.questions.has-owner'),
true
);
$input->setOption('has-owner', $has_owner);
}
/**
@@ -158,9 +171,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$base_path = $input->getOption('base-path')?:'/admin/structure';
$learning = $input->getOption('learning')?:false;
$bundle_entity_type = $has_bundles ? $entity_name . '_type' : null;
$is_translatable = $input->getOption('is-translatable')? : true;
$revisionable = $input->getOption('revisionable')? :false;
$has_forms = $input->getOption('has-forms')?:true;
$is_translatable = $input->getOption('is-translatable');
$revisionable = $input->getOption('revisionable');
$has_forms = $input->getOption('has-forms');
$has_owner = $input->getOption('has-owner');
$generator = $this->generator;
@@ -178,6 +192,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'is_translatable' => $is_translatable,
'revisionable' => $revisionable,
'has_forms' => $has_forms,
'has_owner' => $has_owner,
]);
if ($has_bundles) {
@@ -187,7 +202,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
'--entity-class' => $entity_class . 'Type',
'--entity-name' => $entity_name . '_type',
'--label' => $label . ' type',
'--bundle-of' => $entity_name
'--bundle-of' => $entity_name,
'--no-interaction'
]
);
}
@@ -9,7 +9,9 @@ namespace Drupal\{{ module }}\Entity;
{% endblock %}

{% block use_class %}
{% if has_owner %}
use Drupal\Core\Entity\EntityStorageInterface;
{% endif %}
use Drupal\Core\Field\BaseFieldDefinition;
{% if revisionable %}
use Drupal\Core\Entity\RevisionableContentEntityBase;
@@ -20,7 +22,9 @@ use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityPublishedTrait;
use Drupal\Core\Entity\EntityTypeInterface;
{% if has_owner %}
use Drupal\user\UserInterface;
{% endif %}
{% endblock %}

{% block class_declaration %}
@@ -79,7 +83,9 @@ use Drupal\user\UserInterface;
{% endif %}
* "label" = "name",
* "uuid" = "uuid",
{% if has_owner %}
* "uid" = "user_id",
{% endif %}
* "langcode" = "langcode",
* "published" = "status",
* },
@@ -124,6 +130,7 @@ class {{ entity_class }} extends {% if revisionable %}RevisionableContentEntityB
{% endblock %}

{% block class_methods %}
{% if has_owner %}

/**
* {@inheritdoc}
@@ -134,6 +141,7 @@ class {{ entity_class }} extends {% if revisionable %}RevisionableContentEntityB
'user_id' => \Drupal::currentUser()->id(),
];
}
{% endif %}
{% if revisionable %}

/**
@@ -157,8 +165,8 @@ class {{ entity_class }} extends {% if revisionable %}RevisionableContentEntityB
*/
public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage);

{% if is_translatable %}

foreach (array_keys($this->getTranslationLanguages()) as $langcode) {
$translation = $this->getTranslation($langcode);

@@ -206,6 +214,7 @@ class {{ entity_class }} extends {% if revisionable %}RevisionableContentEntityB
$this->set('created', $timestamp);
return $this;
}
{% if has_owner %}

/**
* {@inheritdoc}
@@ -236,6 +245,7 @@ class {{ entity_class }} extends {% if revisionable %}RevisionableContentEntityB
$this->set('user_id', $account->id());
return $this;
}
{% endif %}

/**
* {@inheritdoc}
@@ -245,6 +255,7 @@ class {{ entity_class }} extends {% if revisionable %}RevisionableContentEntityB

// Add the published field.
$fields += static::publishedBaseFieldDefinitions($entity_type);
{% if has_owner %}

$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Authored by'))
@@ -272,6 +283,7 @@ class {{ entity_class }} extends {% if revisionable %}RevisionableContentEntityB
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
{% endif %}

$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
@@ -15,7 +15,9 @@ use Drupal\Core\Entity\RevisionLogInterface;
{% endif %}
use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\Core\Entity\EntityPublishedInterface;
{% if has_owner %}
use Drupal\user\EntityOwnerInterface;
{% endif %}
{% endblock %}

{% block class_declaration %}
@@ -24,7 +26,7 @@ use Drupal\user\EntityOwnerInterface;
*
* @ingroup {{module}}
*/
interface {{ entity_class }}Interface extends ContentEntityInterface{% if revisionable %}, RevisionLogInterface{% endif %}, EntityChangedInterface, EntityPublishedInterface, EntityOwnerInterface {% endblock %}
interface {{ entity_class }}Interface extends ContentEntityInterface{% if revisionable %}, RevisionLogInterface{% endif %}, EntityChangedInterface, EntityPublishedInterface{% if has_owner %}, EntityOwnerInterface{% endif %} {% endblock %}
{% block class_methods %}
/**
* Add get/set methods for your configuration properties here.
@@ -67,8 +69,8 @@ interface {{ entity_class }}Interface extends ContentEntityInterface{% if revisi
* The called {{ label }} entity.
*/
public function setCreatedTime($timestamp);

{% if revisionable %}

/**
* Gets the {{ label }} revision creation timestamp.
*

0 comments on commit 6fb6004

Please sign in to comment.
You can’t perform that action at this time.