Currently, the block_admin_configure_submit() submit handler runs queries directly rather than calling any API function. I think this is not a good practice. It seems to me it would be better to have the block-saving functionality factored out into a block_save() API function -- analogous to node_save() -- that could be reused elsewhere. In D7 a lot of these issues have been fixed (logic has been moved out of submit handlers into API) -- but clearly there are still instances of it.

Comments

xjm’s picture

pwolanin brought a relevant point on IRC -- maybe blocks should act like proper entities?

Relevant issues:
#430886: Make all blocks fieldable entities
#1164718: Improving the usability between "custom block" and "content"

SilviaT’s picture

sub

joachim’s picture

Before we write a block_save() we need to figure out an object schema for the block object.

block_load() only loads from the {block} table, but block_admin_configure_submit() needs to also write to {block_role}.

pfrenssen’s picture

Status: Active » Closed (duplicate)

This seems to be solved by the Configuration Management and Blocks Everywhere initiatives in D8. It will be possible to manipulate blocks with the config API:

  $config = config($block['config_id']);
  $config->set('weight', $block['weight']);
  $config->set('region', $block['region']);
  $config->save();

Marking this as a duplicate of #1535868: Convert all blocks into plugins.