Making block editor fields readonly

edited June 2014 in Share
I need to grant a user access to modify fuel blocks. But I don't want him to be able to edit the "Name" or "Description" of the block. They should be only able to edit the "View" of the block. Is it possible to make some fields readonly for specific users?

Comments

  • edited 8:13AM
    Unfortunately, that is currently not possible without modifying the model's form_fields method to look for permissions associated with the user.

    If you are feeling adventurous, there is a "module_overwrites" configuration found in the fuel/application/config/MY_fuel_modules.php that can be used to overwrite configuration parameters for a module. This includes the model associated with the module. So, you could extend the Fuel_blocks_model.php file with a file called MY_blocks_model.php and place the file in the fuel/application/models folder. Then add the following to the MY_fuel_modules file:
    $config['module_overwrites']['blocks']['model_name'] = 'my_blocks_model';
    You could then add your own specific permissions in the Permissions module and then in your model's form_fields method before you return the $fields array, you could use the Fuel_auth::has_permission() method:
    ... if (!$this->fuel->auth->has_permission('edit_block_name')) { // one method unset($fields['name']); // OR... you can change the type to hidden $fields['name']['type'] = 'hidden'; } return $fields; ...
    This is just for display purposes so you may want to add something in an on_before_save or on_before_validate hook that checks the permission as well and if they don't have that permission, you can reset it to the currently saved value.
    function on_before_save($values){ if (!empty($values['id'])) { if (!$this->fuel->auth->has_permission('edit_block_name')) { $orig = $this->find_by_key($values['id']); $values['name'] = $orig->name; } } return $values; }
Sign In or Register to comment.