public function edit()
    {
        if (!userHasPermission('admin:blog:tag:' . $this->blog->id . ':edit')) {

            unauthorised();
        }

        // --------------------------------------------------------------------------

        $this->data['tag'] = $this->blog_tag_model->getById($this->uri->segment(6));

        if (empty($this->data['tag'])) {

            show404();
        }

        // --------------------------------------------------------------------------

        if ($this->input->post()) {

            $oFormValidation = Factory::service('FormValidation');

            $oFormValidation->set_rules('label', '', 'required');
            $oFormValidation->set_rules('description', '', '');
            $oFormValidation->set_rules('seo_title', '', 'max_length[150]');
            $oFormValidation->set_rules('seo_description', '', 'max_length[300]');
            $oFormValidation->set_rules('seo_keywords', '', 'max_length[150]');

            $oFormValidation->set_message('required', lang('fv_required'));
            $oFormValidation->set_message('max_length', lang('fv_max_length'));

            if ($oFormValidation->run()) {

                $aUpdateData                    = array();
                $aUpdateData['label']           = $this->input->post('label');
                $aUpdateData['description']     = $this->input->post('description');
                $aUpdateData['seo_title']       = $this->input->post('seo_title');
                $aUpdateData['seo_description'] = $this->input->post('seo_description');
                $aUpdateData['seo_keywords']    = $this->input->post('seo_keywords');

                if ($this->blog_tag_model->update($this->data['tag']->id, $aUpdateData)) {

                    $this->session->set_flashdata('success', 'Tag saved successfully.');
                    redirect('admin/blog/tag/index/' . $this->blog->id . $this->isModal);

                } else {

                    $this->data['error']  = 'There was a problem saving the Tag. ';
                    $this->data['error'] .= $this->blog_tag_model->lastError();
                }

            } else {

                $this->data['error'] = lang('fv_there_were_errors');
            }
        }

        // --------------------------------------------------------------------------

        //  Page data
        $this->data['page']->title = 'Blog &rsaquo; Catrgories &rsaquo; Edit &rsaquo; ' . $this->data['tag']->label;

        // --------------------------------------------------------------------------

        //  Fetch data
        $this->data['tags'] = $this->blog_tag_model->getAll();

        // --------------------------------------------------------------------------

        //  Load views
        Helper::loadView('edit');
    }