An HTML form to edit block settings

@param Tree $tree
@param int  $block_id

@return void
8777
public function editBlockConfiguration(Tree $tree, int $block_id): void
    {
        $PEDIGREE_ROOT_ID = $tree->getPreference('PEDIGREE_ROOT_ID');
        $gedcomid         = $tree->getUserPreference(Auth::user(), 'gedcomid');

        $type = $this->getBlockSetting($block_id, 'type', 'pedigree');
        $pid  = $this->getBlockSetting($block_id, 'pid', Auth::check() ? ($gedcomid ?: $PEDIGREE_ROOT_ID) : $PEDIGREE_ROOT_ID);

        $charts = [
            'pedigree'    => I18N::translate('Pedigree'),
            'descendants' => I18N::translate('Descendants'),
            'hourglass'   => I18N::translate('Hourglass chart'),
            'treenav'     => I18N::translate('Interactive tree'),
        ];
        uasort($charts, 'Fisharebest\Webtrees\I18N::strcasecmp');

        $individual = Individual::getInstance($pid, $tree);

        echo view('modules/charts/config', [
            'charts'     => $charts,
            'individual' => $individual,
            'tree'       => $tree,
            'type'       => $type,
        ]);
    }
461833
public function menuChangeBlocks(Tree $tree): ?Menu
    {
        $request = app(ServerRequestInterface::class);

        if (Auth::check() && $request->get('route') === 'user-page') {
            return new Menu(I18N::translate('Customize this page'), route('user-page-edit', ['ged' => $tree->name()]), 'menu-change-blocks');
        }

        if (Auth::isManager($tree) && $request->get('route') === 'tree-page') {
            return new Menu(I18N::translate('Customize this page'), route('tree-page-edit', ['ged' => $tree->name()]), 'menu-change-blocks');
        }

        return null;
    }
80465
public function addBlock(Block $block)
	{
		if ($this->lock('block')) {
			$this->matchDiscriminator($block);
			if ($this->addUnique($this->blocks, $block)) {
				$block->setPlaceHolder($this);
			}
			$this->unlock('block');
		}
	}
1237069
public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void
    {
        $this->setBlockSetting($block_id, 'show_last_update', $request->get('show_last_update', ''));
        $this->setBlockSetting($block_id, 'show_common_surnames', $request->get('show_common_surnames', ''));
        $this->setBlockSetting($block_id, 'number_of_surnames', $request->get('number_of_surnames', self::DEFAULT_NUMBER_OF_SURNAMES));
        $this->setBlockSetting($block_id, 'stat_indi', $request->get('stat_indi', ''));
        $this->setBlockSetting($block_id, 'stat_fam', $request->get('stat_fam', ''));
        $this->setBlockSetting($block_id, 'stat_sour', $request->get('stat_sour', ''));
        $this->setBlockSetting($block_id, 'stat_other', $request->get('stat_other', ''));
        $this->setBlockSetting($block_id, 'stat_media', $request->get('stat_media', ''));
        $this->setBlockSetting($block_id, 'stat_repo', $request->get('stat_repo', ''));
        $this->setBlockSetting($block_id, 'stat_surname', $request->get('stat_surname', ''));
        $this->setBlockSetting($block_id, 'stat_events', $request->get('stat_events', ''));
        $this->setBlockSetting($block_id, 'stat_users', $request->get('stat_users', ''));
        $this->setBlockSetting($block_id, 'stat_first_birth', $request->get('stat_first_birth', ''));
        $this->setBlockSetting($block_id, 'stat_last_birth', $request->get('stat_last_birth', ''));
        $this->setBlockSetting($block_id, 'stat_first_death', $request->get('stat_first_death', ''));
        $this->setBlockSetting($block_id, 'stat_last_death', $request->get('stat_last_death', ''));
        $this->setBlockSetting($block_id, 'stat_long_life', $request->get('stat_long_life', ''));
        $this->setBlockSetting($block_id, 'stat_avg_life', $request->get('stat_avg_life', ''));
        $this->setBlockSetting($block_id, 'stat_most_chil', $request->get('stat_most_chil', ''));
        $this->setBlockSetting($block_id, 'stat_avg_chil', $request->get('stat_avg_chil', ''));
    }
1173455
public function getBlock(Tree $tree, int $block_id, string $ctype = '', array $cfg = []): string
    {
        $PEDIGREE_ROOT_ID = $tree->getPreference('PEDIGREE_ROOT_ID');
        $gedcomid         = $tree->getUserPreference(Auth::user(), 'gedcomid');

        $type = $this->getBlockSetting($block_id, 'type', 'pedigree');
        $pid  = $this->getBlockSetting($block_id, 'pid', Auth::check() ? ($gedcomid ?: $PEDIGREE_ROOT_ID) : $PEDIGREE_ROOT_ID);

        extract($cfg, EXTR_OVERWRITE);

        $person = Individual::getInstance($pid, $tree);
        if (!$person) {
            $pid = $PEDIGREE_ROOT_ID;
            $this->setBlockSetting($block_id, 'pid', $pid);
            $person = Individual::getInstance($pid, $tree);
        }

        $title = $this->title();

        if ($person) {
            switch ($type) {
                default:
                case 'pedigree':
                    /** @var PedigreeChartModule $module */
                    $module    = $this->module_service->findByInterface(PedigreeChartModule::class)->first();
                    $title     = $module->chartTitle($person);
                    $chart_url = $module->chartUrl($person, [
                        'ajax'        => true,
                        'generations' => 3,
                        'layout'      => PedigreeChartModule::ORIENTATION_RIGHT,
                    ]);
                    $content   = view('modules/charts/chart', [
                        'block_id'  => $block_id,
                        'chart_url' => $chart_url,
                        'class'     => 'wt-chart-pedigree',
                    ]);
                    break;

                case 'descendants':
                    /** @var DescendancyChartModule $module */
                    $module    = $this->module_service->findByInterface(DescendancyChartModule::class)->first();
                    $title     = $module->chartTitle($person);
                    $chart_url = $module->chartUrl($person, [
                        'ajax'        => true,
                        'generations' => 2,
                        'chart_style' => DescendancyChartModule::CHART_STYLE_TREE,
                    ]);
                    $content   = view('modules/charts/chart', [
                        'block_id'  => $block_id,
                        'chart_url' => $chart_url,
                        'class'     => 'wt-chart-descendants',
                    ]);
                    break;

                case 'hourglass':
                    /** @var HourglassChartModule $module */
                    $module    = $this->module_service->findByInterface(HourglassChartModule::class)->first();
                    $title     = $module->chartTitle($person);
                    $chart_url = $module->chartUrl($person, [
                        'ajax'        => true,
                        'generations' => 2,
                    ]);
                    $content   = view('modules/charts/chart', [
                        'block_id'  => $block_id,
                        'chart_url' => $chart_url,
                        'class'     => 'wt-chart-hourglass',
                    ]);
                    break;

                case 'treenav':
                    /** @var InteractiveTreeModule $module */
                    $module  = $this->module_service->findByInterface(InteractiveTreeModule::class)->first();
                    $title   = I18N::translate('Interactive tree of %s', $person->fullName());
                    $tv      = new TreeView();
                    $content = '<script>$("head").append(\'<link rel="stylesheet" href="' . $module->css() . '" type="text/css" />\');</script>';
                    $content .= '<script src="' . $module->js() . '"></script>';
                    [$html, $js] = $tv->drawViewport($person, 2);
                    $content .= $html . '<script>' . $js . '</script>';
                    break;
            }
        } else {
            $content = I18N::translate('You must select an individual and a chart type in the block preferences');
        }

        if ($ctype !== '') {
            if ($ctype === 'gedcom' && Auth::isManager($tree)) {
                $config_url = route('tree-page-block-edit', [
                    'block_id' => $block_id,
                    'ged'      => $tree->name(),
                ]);
            } elseif ($ctype === 'user' && Auth::check()) {
                $config_url = route('user-page-block-edit', [
                    'block_id' => $block_id,
                    'ged'      => $tree->name(),
                ]);
            } else {
                $config_url = '';
            }

            return view('modules/block-template', [
                'block'      => Str::kebab($this->name()),
                'id'         => $block_id,
                'config_url' => $config_url,
                'title'      => strip_tags($title),
                'content'    => $content,
            ]);
        }

        return $content;
    }
908636
public function edit($id = null) {
		$block = $this->Blocks->get($id, [
			'contain' => []
		]);
		if ($this->request->is(['patch', 'post', 'put'])) {
			$block = $this->Blocks->patchEntity($block, $this->request->data);
			if ($this->Blocks->save($block)) {
				$this->Flash->success('The block has been saved.');
				return $this->redirect(['action' => 'index']);
			} else {
				$this->Flash->error('The block could not be saved. Please, try again.');
			}
		}
		$this->set(compact('block'));
	}
325177
private void initListBlock(final Block root)
    {
        Line line = root.lines;
        line = line.next;
        while (line != null)
        {
            final LineType t = line.getLineType(this.config);
            if ((t == LineType.OLIST || t == LineType.ULIST)
                    || (!line.isEmpty && (line.prevEmpty && line.leading == 0 && !(t == LineType.OLIST || t == LineType.ULIST))))
            {
                root.split(line.previous).type = BlockType.LIST_ITEM;
            }
            line = line.next;
        }
        root.split(root.lineTail).type = BlockType.LIST_ITEM;
    }
692036
public function userPageEdit(Tree $tree, UserInterface $user): ResponseInterface
    {
        $main_blocks = $this->userBlocks($user->id(), 'main');
        $side_blocks = $this->userBlocks($user->id(), 'side');
        $all_blocks  = $this->availableUserBlocks();
        $title       = I18N::translate('Change the “My page” blocks');
        $url_cancel  = route('user-page', ['ged' => $tree->name()]);
        $url_save    = route('user-page-update', ['ged' => $tree->name()]);

        return $this->viewResponse('edit-blocks-page', [
            'all_blocks'  => $all_blocks,
            'can_reset'   => true,
            'main_blocks' => $main_blocks,
            'side_blocks' => $side_blocks,
            'title'       => $title,
            'url_cancel'  => $url_cancel,
            'url_save'    => $url_save,
        ]);
    }
297603
final protected function setBlockSetting(int $block_id, string $setting_name, string $setting_value): self
    {
        DB::table('block_setting')->updateOrInsert([
            'block_id'      => $block_id,
            'setting_name'  => $setting_name,
        ], [
            'setting_value' => $setting_value,
        ]);

        return $this;
    }
337277
public void updateToRemovedBlock(boolean add, long blockId) {
    if (add) {
      if (mBlocks.contains(blockId)) {
        mToRemoveBlocks.add(blockId);
      }
    } else {
      mToRemoveBlocks.remove(blockId);
    }
  }
759927
public function postAdminEditAction(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $block_id    = (int) $request->get('block_id');
        $xref        = $request->get('xref', '');
        $story_body  = $request->get('story_body', '');
        $story_title = $request->get('story_title', '');
        $languages   = $request->get('languages', []);

        if ($block_id !== 0) {
            DB::table('block')
                ->where('block_id', '=', $block_id)
                ->update([
                    'gedcom_id' => $tree->id(),
                    'xref'      => $xref,
                ]);
        } else {
            DB::table('block')->insert([
                'gedcom_id'   => $tree->id(),
                'xref'        => $xref,
                'module_name' => $this->name(),
                'block_order' => 0,
            ]);

            $block_id = (int) DB::connection()->getPdo()->lastInsertId();
        }

        $this->setBlockSetting($block_id, 'story_body', $story_body);
        $this->setBlockSetting($block_id, 'title', $story_title);
        $this->setBlockSetting($block_id, 'languages', implode(',', $languages));

        $url = route('module', [
            'module' => $this->name(),
            'action' => 'Admin',
            'ged'    => $tree->name(),
        ]);

        return redirect($url);
    }
374141
public function getBlock(Tree $tree, int $block_id, string $ctype = '', array $cfg = []): string
    {
        $gedcomid   = $tree->getUserPreference(Auth::user(), 'gedcomid');
        $individual = Individual::getInstance($gedcomid, $tree);
        $links      = [];

        $pedigree_chart = $this->module_service->findByComponent(ModuleChartInterface::class, $tree, Auth::user())
            ->first(static function (ModuleInterface $module): bool {
                return $module instanceof PedigreeChartModule;
            });

        if ($individual instanceof Individual) {
            if ($pedigree_chart instanceof PedigreeChartModule) {
                $links[] = [
                    'url'   => $pedigree_chart->chartUrl($individual),
                    'title' => I18N::translate('Default chart'),
                    'icon'  => 'icon-pedigree',
                ];
            }

            $links[] = [
                'url'   => $individual->url(),
                'title' => I18N::translate('My individual record'),
                'icon'  => 'icon-indis',
            ];
        }

        $links[] = [
            'url'   => route('my-account', []),
            'title' => I18N::translate('My account'),
            'icon'  => 'icon-mypage',
        ];
        $content = view('modules/user_welcome/welcome', ['links' => $links]);

        $real_name = '<span dir="auto">' . e(Auth::user()->realName()) . '</span>';

        /* I18N: A %s is the user’s name */
        $title = I18N::translate('Welcome %s', $real_name);

        if ($ctype !== '') {
            return view('modules/block-template', [
                'block'      => Str::kebab($this->name()),
                'id'         => $block_id,
                'config_url' => '',
                'title'      => $title,
                'content'    => $content,
            ]);
        }

        return $content;
    }
1101567
synchronized void addBlock(Block block) {
    if (!isInitialized()) {
      return;
    }
    
    BlockScanInfo info = blockMap.get(block);
    if ( info != null ) {
      LOG.warn("Adding an already existing block " + block);
      delBlockInfo(info);
    }
    
    info = new BlockScanInfo(block);    
    info.lastScanTime = getNewBlockScanTime();
    
    addBlockInfo(info);
    adjustThrottler();
  }
1055888
protected function setChildren(Block $block)
    {
        if (method_exists($block, 'setChildren')) {
            $children = $this->environment->getBlockChildren($block);
            $block->setChildren($children);
        }
    }
939977
private function updateUserBlocks(int $user_id, array $main_blocks, array $side_blocks): void
    {
        $existing_block_ids = DB::table('block')
            ->where('user_id', '=', $user_id)
            ->pluck('block_id');

        // Deleted blocks
        foreach ($existing_block_ids as $existing_block_id) {
            if (!in_array($existing_block_id, $main_blocks, false) && !in_array($existing_block_id, $side_blocks, false)) {
                DB::table('block_setting')
                    ->where('block_id', '=', $existing_block_id)
                    ->delete();

                DB::table('block')
                    ->where('block_id', '=', $existing_block_id)
                    ->delete();
            }
        }

        $updates = [
            'main' => $main_blocks,
            'side' => $side_blocks,
        ];

        foreach ($updates as $location => $updated_blocks) {
            foreach ($updated_blocks as $block_order => $block_id) {
                if (is_numeric($block_id)) {
                    // Updated block
                    DB::table('block')
                        ->where('block_id', '=', $block_id)
                        ->update([
                            'block_order' => $block_order,
                            'location'    => $location,
                        ]);
                } else {
                    // New block
                    DB::table('block')->insert([
                        'user_id'     => $user_id,
                        'location'    => $location,
                        'block_order' => $block_order,
                        'module_name' => $block_id,
                    ]);
                }
            }
        }
    }
504171
public function replaceBlock(BlockElement $block, array $children = null)
    {
        if ($parent = $block->getParent()) {
            foreach (array_reverse($children ?: $block->getChildren()) as $child) {
                $parent->insertAfter($block, $child);
            }
            $previous = $block->getPreviousSibling();
            if ($previous instanceof TextElement) {
                $previous->setEnd(true);
            }
            $block->remove();
        }
    }
959195
def setBlockRequested(blockInfo, bool)
      if bool
        @requestedBlocks.set blockInfo.blockIndex
      else
        @requestedBlocks.clear blockInfo.blockIndex
      end
    end