Hello,

I have a question. ''The field License duration is locked and cannot be edited.'' It is not good when it is always visible for usual visitors who could create a product. Is there a possibility to hide the field License Duration (commerce_license_duration)?

Comments

bojanz’s picture

Status: Active » Fixed

Sure, hook_form_alter is your friend :) Give the field the desired value, then hide it (#access => FALSE).
You can also use hook_field_widget_form_alter().

gladiatorhl2’s picture

I understand that there is no module. It might also be quite useful for others to make the feature.

I'll try your proposal. Thanks. Is there a way to restrict it by role too? For example, it would be useful for me as administrator to see it but not authorised users.

bojanz’s picture

Under normal circumstances, this field should never be hidden. The ones who can create the product must set the field.
So what you have is a potentially problematic edge case and it can't be a feature in the module.
Your alter hook can check the role of the global user if desired.

gladiatorhl2’s picture

I suppose that the default value could be set by an administrator and hidden from authorised visitors and it would be logical in my opinion. What do you think?

bojanz’s picture

You either are a product admin and can create a product, or you can't.
Yours is an odd middle ground.

gladiatorhl2’s picture

Maybe I am missing something. I will describe my situation a little bit in detail. I have created a website and I agree with you that a product type is created by an administrator. In my website there is a content type which a product reference field is attached to (Inline Entity form widget). So this content type can be created by an authorised visitor or not. Of course, there are some cases when you wouldn't allow to choose freely a limited or unlimited license. I would like to have it as an unlimited one all the time for a creator of an item to sell. Unfortunately, the field License Duration can only be tuned in a Product Type->Product.

There is no automatically created separate field ''License Duration'' in the content type or in the product reference field.

Actually there is the same question about the Status (Product module status form element) in the Product (active or not). I would like to hide it in order to avoid unnecessary questions from authorised visitors who could justifiably ask why this status appears to be in this content type and what it is supposed to mean.

What would you recommend?

bojanz’s picture

Since you're using Inline Entity Form, you can use hook_inline_entity_form_entity_form_alter().

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.