Fork CMS Documentation

website·Indexed 35 days ago

https://docs.fork-cms.com/

Developer guides and user manuals for Fork CMS, covering module development, theming with Twig, media library integration, and system configuration including cronjobs and SEO.

Tokens
32.4K
Snippets
123
Records
235
Agent score
59%

What's inside Fork CMS

  1. Overview of Fork CMS Docker development environment

    Fork CMS provides a containerized PHP development environment using a docker-compose stack. This allows developers to run the website without manually installing PHP, Apache, or MariaDB on their local machine. The default environment includes PHP 7.1 (with GD2, pdo, zip, intl, and XDebug), Apache, and the latest MariaDB. The setup is managed via a Dockerfile for image configuration and a docker-compose.yml file for service orchestration.
  2. Implement a data grid in a Fork CMS backend module

    Data grids are used in the backend to provide an overview of items. To implement a data grid, you must define a parameterized SQL query in your model (without an ORDER BY clause) and then instantiate a BackendDataGridDatabase object within your action's execute method. The grid automatically displays columns returned by the SQL query using the column names as labels.
    // In Model.php
    class Model
    {
        const QUERY_DATAGRID_BROWSE = 
            'SELECT i.id, i.title, UNIX_TIMESTAMP(i.created) AS created, i.user_id 
             FROM mini_blog AS i WHERE i.publish = ? AND i.language = ?';
    }
    
    // In Action/Index.php
    use Backend\Core\Engine\DataGridDatabase as BackendDataGridDatabase;
    
    private function loadDataGrid($published)
    {
        $dg = new BackendDataGridDatabase(
            BackendMiniBlogModel::QUERY_DATAGRID_BROWSE, 
            array($published, BL::getWorkingLanguage())
        );
        return $dg;
    }
  3. Understand Fork CMS dashboard widgets

    The Fork CMS dashboard provides several widgets to monitor website activity:

    • Traffic sources: Displays 'Websites' (referring sites ordered by click volume) and 'Keywords' (terms used in search engines to find the site).
    • Blog comments: Shows the latest blog comments; clicking a comment allows for moderation.
    • Mailmotor: Provides overviews of recent email subscriptions, unsubscriptions (including timestamps), and basic statistics for the last sent newsletter.
  4. Understand Fork CMS locale types

    Fork CMS categorizes translations into four distinct types based on their usage and constraints:

    • lbl (Labels): Short literal translations (single words or short phrases). They cannot contain HTML. Do not capitalize the first letter unless required by the language (e.g., German nouns), as capitalization should be handled by template modifiers.
    • msg (Messages): Longer sentences that may contain HTML tags.
    • err (Error Messages): Sentences specifically used for error reporting, separated from regular messages.
    • act (Actions): Slugs used in URLs. They must not contain spaces or special characters that interfere with URL structures (like question marks).
  5. Manage mailing list subscriptions with Mailmotor

    Mailmotor allows website visitors to subscribe or unsubscribe from a mailing list. It supports integration with external mail services to automate this process. Supported configurations include:

    • Campaign Monitor
    • MailChimp
    • None (Manual): You will receive an email notification whenever a user requests to subscribe or unsubscribe, allowing you to handle the request manually.
    • Custom: You can extend the system to hook into your own external mail service.
  6. Understand how themes override core templates in Fork CMS

    Themes in Fork CMS provide a mechanism to override core templates without modifying the core files directly. This ensures that core updates do not overwrite customizations. Fork CMS mirrors the core file structure within the theme folder; if a file exists in both the core and the theme folder, the version in the theme folder takes precedence. Developers only need to include the specific files they wish to change in the theme folder rather than duplicating the entire core structure.
  7. Implement pagination in a Fork CMS module

    To implement pagination on an overview page, you must calculate the current page offset and limit, validate that the requested page exists, and fetch the corresponding subset of records from the model.

    Key pagination parameters include:

    • url: The base URL used to generate pagination links (appends the ?page= variable).
    • limit: The maximum number of items per page (typically sourced from a backend setting).
    • num_items: The total count of visible/published items.
    • num_pages: The total number of pages, calculated as ceil(num_items / limit).
    • requested_page: The page number requested by the user via the URL.
    • offset: The starting item index for the database query, calculated as (requested_page * limit) - limit.
    use Frontend\Core\Engine\Navigation as FrontendNavigation;
    use Frontend\Core\Engine\Model as FrontendModel;
    use Frontend\Modules\MiniBlog\Engine\Model as FrontendMiniBlogModel;
    use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
    
    // 1. Initialize pagination data
    protected $pagination = array(
    	'limit' => 10,
    	'offset' => 0,
    	'requested_page' => 1,
    	'num_items' => null,
    	'num_pages' => null
    );
    
    // 2. Calculate parameters
    $requestedPage = $this->url->getParameter('page', 'int', 1);
    
    $this->pagination['url'] = FrontendNavigation::getUrlForBlock('mini_blog');
    $this->pagination['limit'] = FrontendModel::getModuleSetting('mini_blog', 'overview_num_items', 10);
    $this->pagination['num_items'] = FrontendMiniBlogModel::getAllCount();
    $this->pagination['num_pages'] = (int) ceil($this->pagination['num_items'] / $this->pagination['limit']);
    $this->pagination['requested_page'] = $requestedPage;
    $this->pagination['offset'] = ($this->pagination['requested_page'] * $this->pagination['limit']) - $this->pagination['limit'];
    
    // 3. Validate page existence
    if($this->pagination['num_pages'] == 0) $this->pagination['num_pages'] = 1;
    if($requestedPage > $this->pagination['num_pages'] || $requestedPage < 1) {
         throw new NotFoundHttpException();
    }
    
    // 4. Fetch the paginated records
    $this->records = FrontendMiniBlogModel::getAll($this->pagination['limit'], $this->pagination['offset']);
  8. Manage page hierarchy and organization

    Pages in Fork CMS are organized in a hierarchical overview on the left side of the pages tab. They are structured under three default directories: 'Main navigation', 'footer navigation', and 'single pages'. Pages placed in 'single pages' are excluded from the navigation structure and are only accessible via direct links. Users can drag and drop pages to change their order, hierarchy, or directory.
  9. Interpret Google Analytics metrics in Fork CMS

    The Marketing module provides an analytics overview based on Google Analytics data. To ensure accurate insights, users should verify the date range using the 'Change period' button. The system provides several key performance indicators (KPIs) to measure website traffic:

    • Pageviews: Total number of pages viewed (includes repeat views of the same page).
    • Pages per visit: Calculated as Pageviews divided by Visitors.
    • New visits percentage: The proportion of first-time visitors.
    • Visitors: The number of unique visitors.
    • Average time on site: Indicates user engagement and interest.
    • Bounce rate: The percentage of visitors who leave after viewing only one page.

    Additionally, the module provides a 'Recent visits timeline' for temporal trends, a 'Page per traffic source diagram' for acquisition channels, and lists for 'Top referrers' and 'Top keywords'.

  10. Understand Fork CMS URL routing priority

    When a URL is accessed, Fork CMS follows a specific priority sequence to determine what to serve:

    1. Physical Location: The .htaccess file first checks if the URL corresponds to an existing file or folder on the disk. If so, that file/folder is served.
    2. Front Controller: If no physical file exists, the request is rewritten to /index.php, which initiates the application router.
    3. Application Mapping: The router assigns the request to an application based on the URL prefix:
      • /private or /backend $\rightarrow$ Backend application
      • /api $\rightarrow$ API application
      • /install $\rightarrow$ Install application
      • All other paths (/*) $\rightarrow$ Frontend application
  11. Manage media files using MediaLibrary entities

    The MediaLibrary module provides a centralized way to store images, files, movies, and audio files. These files are treated as MediaItem entities. To organize these items, the module uses MediaGroup entities, which are collections of MediaItem entities. MediaGroup entities can be integrated into custom module entities to associate media with specific content (e.g., adding a gallery of images to a blog article).
    class BlogArticle
    {
        /**
         * @var MediaGroup
         */
        private $images;
    
        /**
         * @var MediaGroup
         */
        private $trailers;
    }