You are here

public function EditOwnContactInformationBlock::build in CRM Core 8

Same name and namespace in other branches
  1. 8.3 modules/crm_core_user_sync/src/Plugin/Block/EditOwnContactInformationBlock.php \Drupal\crm_core_user_sync\Plugin\Block\EditOwnContactInformationBlock::build()

Builds and returns the renderable array for this block plugin.

If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

See also

\Drupal\block\BlockViewBuilder

File

modules/crm_core_user_sync/src/Plugin/Block/EditOwnContactInformationBlock.php, line 110

Class

EditOwnContactInformationBlock
Provides a 'Edit own contact information' block.

Namespace

Drupal\crm_core_user_sync\Plugin\Block

Code

public function build() {
  if ($individualId = $this->relation
    ->getUserIndividualId($this->accountProxy
    ->id())) {

    /* @var $individual \Drupal\crm_core_contact\Entity\Individual */

    /* @var $form \Drupal\crm_core_contact\Form\IndividualForm */
    $individual = Individual::load($individualId);
    $form = $this->entityTypeManager
      ->getFormObject($individual
      ->getEntityTypeId(), 'default');
    $form
      ->setEntity($individual);
    $form_state = new FormState();
    $form_state
      ->disableRedirect();
    $build = $this->formBuilder
      ->buildForm($form, $form_state);
    unset($build['actions']['delete']);
    return $build;
  }
}