Skip to content

Commit

Permalink
Merge pull request #219 from jmolivas/content-entity-fix
Browse files Browse the repository at this point in the history
Content entity fix
  • Loading branch information
jmolivas committed Oct 14, 2014
2 parents 8174f2e + 09fcdf1 commit 133fecb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Drupal\{{module}}\Entity\Controller;
{% block use_class %}
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Url;
{% endblock %}

{% block class_declaration %}
Expand Down Expand Up @@ -38,10 +39,14 @@ class {{ entity_class }}ListController extends EntityListBuilder
public function buildRow(EntityInterface $entity) {
/* @var $entity \Drupal\{{module}}\Entity\{{ entity_class }} */
$row['id'] = $entity->id();
$row['name'] = \Drupal::l($this->getLabel($entity),
'{{ entity_name }}.list', array(
'{{module}}_{{ entity_name }}' => $entity->id(),
));
$row['name'] = \Drupal::l(
$this->getLabel($entity),
new Url(
'{{ entity_name }}.edit', array(
'bar' => $entity->id(),
)
)
);
return $row + parent::buildRow($entity);
}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ class {{ entity_class }}DeleteForm extends ContentEntityConfirmFormBase
/**
* {@inheritdoc}
*/
public function submit(array $form, FormStateInterface $form_state) {
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->delete();

watchdog('content', '@type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $this->entity->label()));
$form_state->setRedirect('{{ entity_name }}.list');
\Drupal::logger('{{module}}')->notice('content @type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $this->entity->label()));
$form_state->setRedirectUrl($this->getCancelUrl());
}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class {{ entity_class }}Form extends ContentEntityForm
public function submit(array $form, FormStateInterface $form_state) {
// Build the entity object from the submitted values.
$entity = parent::submit($form, $form_state);
$form_state->setRedirect('{{ entity_name }}.list');

return $entity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Drupal\{{module}};
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
{% endblock %}

{% block class_declaration %}
Expand All @@ -31,26 +32,26 @@ class {{ entity_class }}AccessControlHandler extends EntityAccessControlHandler

switch ($operation) {
case 'view':
return $account->hasPermission('view {{ entity_class }} entity');
return AccessResult::allowedIfHasPermission($account, 'view {{ entity_class }} entity');
break;

case 'edit':
return $account->hasPermission('edit {{ entity_class }} entity');
return AccessResult::allowedIfHasPermission($account, 'edit {{ entity_class }} entity');
break;

case 'delete':
return $account->hasPermission('delete {{ entity_class }} entity');
return AccessResult::allowedIfHasPermission($account, 'delete {{ entity_class }} entity');
break;

}

return TRUE;
return AccessResult::allowed();
}

/**
* {@inheritdoc}
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return $account->hasPermission('add {{ entity_class }} entity');
return AccessResult::allowedIfHasPermission($account, 'add Bar entity');
}
{% endblock %}

0 comments on commit 133fecb

Please sign in to comment.