-1

i have a custom entity content : Product. I am looking for a way to give the posibility to change the url of the product like this block :

enter image description here

Block on the right.

It's a screen of article content.

Here my annotation for my entity content :

/**
 * Defines the Produits entity.
 *
 * @ingroup boutique
 *
 * @ContentEntityType(
 *   id = "produits_entity",
 *   label = @Translation("Produits"),
 *   handlers = {
 *     "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
 *     "list_builder" = "Drupal\boutique\ProduitsEntityListBuilder",
 *     "views_data" = "Drupal\boutique\Entity\ProduitsEntityViewsData",
 *
 *     "form" = {
 *       "default" = "Drupal\boutique\Form\ProduitsEntityForm",
 *       "add" = "Drupal\boutique\Form\ProduitsEntityForm",
 *       "edit" = "Drupal\boutique\Form\ProduitsEntityForm",
 *       "delete" = "Drupal\boutique\Form\ProduitsEntityDeleteForm",
 *     },
 *     "access" = "Drupal\boutique\ProduitsEntityAccessControlHandler",
 *     "route_provider" = {
 *       "html" = "Drupal\boutique\ProduitsEntityHtmlRouteProvider",
 *     },
 *   },
 *   base_table = "produits_entity",
 *   admin_permission = "administer produits entities",
 *   entity_keys = {
 *     "id" = "id",
 *     "label" = "name",
 *     "uuid" = "uuid",
 *     "uid" = "user_id",
 *     "langcode" = "langcode",
 *     "status" = "status",
 *   },
 *
 *   links = {
 *     "canonical" = "/produits/{produits_entity}",
 *     "add-form" = "/admin/boutique/produits/add",
 *     "edit-form" = "/admin/boutique/produits/{produits_entity}/edit",
 *     "delete-form" = "/admin/boutique/produits/{produits_entity}/delete",
 *     "collection" = "/admin/boutique/produits/liste",
 *   },
 *   field_ui_base_route = "produits_entity.settings"
 * )
 */

Is there a way for extend my entity content to the node properties ?

5
  • Do you want an option to "publish" or "unpublish" your entity content in your custom content entity - product? Jun 21, 2016 at 9:19
  • 1
    See drupal.org/node/2655780. It will not give you the vertical tabs, that is not specific but a setting to add a url alias field to any content entity.
    – Berdir
    Jun 21, 2016 at 9:20
  • 1
    Or you can define it as a field yourself, like pathauto_entity_base_field_info() does for node.
    – Berdir
    Jun 21, 2016 at 9:20
  • i want just the possibility for the user or path auto to change the path. I ll check your link Berdir thx
    – Kevin
    Jun 21, 2016 at 9:27
  • i think the better way is to create a custom field for the path... i ll try to implement that.
    – Kevin
    Jun 21, 2016 at 11:36

1 Answer 1

0

This is how i have solve my problem (don't work with pathauto):

I create a custom field in my form for the path :

enter image description here

And in my submit :

i use the

$path = \Drupal::service('path.alias_storage')->save($system_path, $path_alias, $langcode);

 public function save(array $form, FormStateInterface $form_state) {
    $entity = $this->entity;
    $status = parent::save($form, $form_state);


    switch ($status) {
      case SAVED_NEW:
        drupal_set_message($this->t('Created the %label Produits.', [
          '%label' => $entity->label(),
        ]));

        $path = \Drupal::service('path.alias_storage')->save('/produits/'.$entity->id(), $form_state->getValue('path')[0]['value'], 'fr');

        break;

      default:
        drupal_set_message($this->t('Saved the %label Produits.', [
          '%label' => $entity->label(),
        ]));
    }
    $form_state->setRedirect('entity.produits_entity.canonical', ['produits_entity' => $entity->id()]);
  }

Now i need to work with the service path.alias_storage when user modify and delete my product.

1
  • Don't forget that drupal is open source and you can always look how the feature is implemented in the node entity.
    – Eyal
    Jun 21, 2016 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.