### Database Setup and Asset Installation Commands Source: https://context7.com/setono/syliustermsplugin/llms.txt Provides essential console commands for setting up and managing the plugin's database schema and frontend assets. This includes generating and migrating database changes and installing public assets. ```bash # Database setup php bin/console doctrine:migrations:diff php bin/console doctrine:migrations:migrate # Install assets php bin/console assets:install ``` -------------------------------- ### Install Sylius Terms Plugin with Composer Source: https://github.com/setono/syliustermsplugin/blob/2.x/README.md This command downloads the Sylius terms plugin using Composer. It's the first step in integrating the plugin into your Sylius project. ```bash composer require setono/sylius-terms-plugin ``` -------------------------------- ### Update Database Schema for Sylius Terms Plugin Source: https://github.com/setono/syliustermsplugin/blob/2.x/README.md These bash commands are used to generate and apply database migrations after installing the Sylius terms plugin. This ensures your database schema is up-to-date with the plugin's requirements. ```bash $ php bin/console doctrine:migrations:diff $ php bin/console doctrine:migrations:migrate ``` -------------------------------- ### TermsProvider Service: Get Checkout Terms (PHP) Source: https://context7.com/setono/syliustermsplugin/llms.txt Retrieves all enabled terms for the checkout complete form that are associated with the current channel and locale. It utilizes the TermsProviderInterface to fetch the terms and iterates through them to display their name and code. ```php termsProvider->getTerms(CompleteType::class); foreach ($terms as $term) { echo sprintf( "Term: %s (code: %s)\n", $term->getName(), $term->getCode() ); } return $terms; } } ``` -------------------------------- ### Import Sylius Terms Plugin Routes Source: https://github.com/setono/syliustermsplugin/blob/2.x/README.md This YAML configuration imports the routes for the Sylius terms plugin. Ensure this is added to your config/routes/ directory. A version for non-localized stores is also available. ```yaml # config/routes/setono_sylius_terms.yaml setono_sylius_terms: resource: "@SetonoSyliusTermsPlugin/Resources/config/routes.yaml" ``` -------------------------------- ### Manage Terms Models and Associations - PHP Source: https://context7.com/setono/syliustermsplugin/llms.txt Illustrates the creation and management of the Terms domain model, including setting translated content, associating terms with channels, and linking them to specific form types for integration. Also shows how to query and remove these associations. ```php setCode('privacy_policy'); $terms->setEnabled(true); // Set translated content (automatically uses current translation) $terms->setName('Privacy Policy'); $terms->setSlug('privacy-policy'); $terms->setLabel('I accept the [link:privacy policy]'); $terms->setContent('

Privacy Policy

Content here...

'); // Associate with channels $terms->addChannel($webChannel); $terms->addChannel($mobileChannel); // Associate with form types where terms should appear $terms->addForm(CompleteType::class); $terms->addForm(CustomerRegistrationType::class); // Query form associations $forms = $terms->getForms(); // Returns: [ // 'Sylius\Bundle\CoreBundle\Form\Type\Checkout\CompleteType', // 'Sylius\Bundle\ShopBundle\Form\Type\Customer\CustomerRegistrationType' // ] // Remove form association $terms->removeForm(CustomerRegistrationType::class); // Check channel association if ($terms->hasChannel($webChannel)) { echo "Terms available on web channel"; } ``` -------------------------------- ### Enable Sylius Terms Plugin in bundles.php Source: https://github.com/setono/syliustermsplugin/blob/2.x/README.md This code snippet shows how to enable the Sylius terms plugin by adding its class to the config/bundles.php file. It's crucial to add the plugin before the Sylius Grid Bundle to avoid configuration errors. ```php ['all' => true], // It is important to add plugin before the grid bundle Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], // ... ]; ``` -------------------------------- ### Defining Routes for Setono Sylius Terms Plugin Source: https://context7.com/setono/syliustermsplugin/llms.txt Defines the routes for the Setono Sylius Terms Plugin in the Symfony application's routing configuration. It points to the plugin's default routes file. ```yaml # config/routes/setono_sylius_terms.yaml setono_sylius_terms: resource: "@SetonoSyliusTermsPlugin/Resources/config/routes.yaml" # For non-localized stores, use: # setono_sylius_terms: # resource: "@SetonoSyliusTermsPlugin/Resources/config/routes_no_locale.yaml" ``` -------------------------------- ### TermsRepository: Find Terms for Form, Slug, or Code (PHP) Source: https://context7.com/setono/syliustermsplugin/llms.txt Provides methods to query terms from the database based on form class, channel, locale, slug, or code. It includes findByFormAndChannelAndLocale, findOneByChannelAndLocaleAndSlug, and findOneByChannelAndLocaleAndCode. It handles cases where terms are not found by throwing exceptions or returning null. ```php termsRepository->findByFormAndChannelAndLocale( $formClass, $channel, $locale ); return $terms; } public function findTermsBySlug( ChannelInterface $channel, string $locale, string $slug ): ?TermsInterface { // Find terms by URL slug (e.g., 'privacy-policy') $terms = $this->termsRepository->findOneByChannelAndLocaleAndSlug( $channel, $locale, $slug ); if ($terms === null) { throw new \Exception("Terms not found for slug: {$slug}"); } return $terms; } public function findTermsByCode( ChannelInterface $channel, string $locale, string $code ): ?TermsInterface { // Find terms by code identifier (e.g., 'terms_and_conditions') return $this->termsRepository->findOneByChannelAndLocaleAndCode( $channel, $locale, $code ); } } ``` -------------------------------- ### PHP Runtime for Generating Terms Links Source: https://context7.com/setono/syliustermsplugin/llms.txt Demonstrates the PHP usage of the TermsRuntime service to generate terms link HTML, typically for embedding in emails or other dynamic content. It requires the TermsRuntime service and the Twig Environment. ```php termsRuntime->link( $this->twig, 'privacy_policy', '@App/email/terms_link.html.twig' ); return "Your account has been created. Please review our {$termsLink}."; } } ``` -------------------------------- ### Plugin Configuration for Terms Forms and Routing Source: https://context7.com/setono/syliustermsplugin/llms.txt Configures the Setono Sylius Terms Plugin, specifying which form types should include terms checkboxes and customizing the URL path prefix for terms pages. It also allows overriding resource classes like model, repository, and controller. ```yaml # config/packages/setono_sylius_terms.yaml setono_sylius_terms: # Define which form types should have terms checkboxes forms: Sylius\Bundle\CoreBundle\Form\Type\Checkout\CompleteType: label: 'Checkout Terms' Sylius\Bundle\ShopBundle\Form\Type\Customer\CustomerRegistrationType: label: 'Registration Terms' App\Form\Type\NewsletterSubscriptionType: label: 'Newsletter Terms' # Customize URL path prefix for terms pages routing: terms: 'terms' # URLs will be /terms/{slug} # Alternative: terms: 'legal' for /legal/{slug} # Override model, repository, or controller classes resources: terms: classes: model: App\Entity\CustomTerms repository: App\Repository\CustomTermsRepository controller: App\Controller\CustomTermsController form: App\Form\Type\CustomTermsType translation: classes: model: App\Entity\CustomTermsTranslation form: App\Form\Type\CustomTermsTranslationType ``` -------------------------------- ### Registering Setono Sylius Terms Plugin in Bundles Source: https://context7.com/setono/syliustermsplugin/llms.txt Registers the Setono Sylius Terms Plugin within the application's bundles configuration. It's important to register this plugin BEFORE SyliusGridBundle. ```php # config/bundles.php return [ // Register plugin BEFORE SyliusGridBundle Setono\SyliusTermsPlugin\SetonoSyliusTermsPlugin::class => ['all' => true], Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], ]; ``` -------------------------------- ### Render Terms Labels with Placeholders - PHP Source: https://context7.com/setono/syliustermsplugin/llms.txt Demonstrates how to use the LabelRenderer to render terms labels, supporting embedded hyperlinks via placeholder syntax like '[link:privacy policy]'. It handles cases with and without placeholders, and when terms content is absent. ```php privacy policy" $html = $this->labelRenderer->render($terms); // If label has no [link:...] placeholder and terms has content: // "I accept the terms" // Renders as: "I accept the terms" // If terms has no content, returns plain label without link: // "This is informational text only" return $html; } } ``` -------------------------------- ### ShowTermsAction Controller: Render Terms Page (PHP) Source: https://context7.com/setono/syliustermsplugin/llms.txt A controller action that renders a terms content page in the shop frontend based on a provided slug. It handles routing, context retrieval (channel and locale), and uses Twig to render the terms content. It can throw a NotFoundHttpException if the terms are not found for the given slug, channel, and locale. ```php getContent(); } catch(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e) { // Thrown when terms with slug 'privacy-policy' doesn't exist // for the current channel and locale echo "Terms page not found"; } ``` -------------------------------- ### Integrate Terms Checkboxes into Forms Dynamically - PHP Source: https://context7.com/setono/syliustermsplugin/llms.txt Shows how to use FormTypeExtension to automatically add terms checkboxes to specified form types. Configuration is done via YAML, and the extension handles fetching terms and adding them as fields with validation constraints. ```php ['label' => 'Checkout Terms'], ] ); // The extension automatically listens to FormEvents::PRE_SET_DATA // When a CompleteType form is built: // 1. Checks if current form type is in configured forms list // 2. Fetches applicable terms via TermsProvider // 3. Adds 'terms' field with TermsCheckboxCollectionType // 4. Each term becomes a checkbox with IsTrue validation constraint // In your checkout template (templates/bundles/SyliusShopBundle/Checkout/Complete/_form.html.twig): // {% if form.terms is defined %} // {{ form_row(form.terms) }} // {% endif %} ``` -------------------------------- ### Generate Terms Links with Twig Extension Source: https://context7.com/setono/syliustermsplugin/llms.txt Generates HTML links to terms pages from Twig templates. It accepts a terms code and an optional custom template for rendering. Outputs an anchor tag or an empty string if the terms do not exist. ```twig {# In any shop template #} {# Generate link to terms by code #} {{ setono_sylius_terms_link('privacy_policy') }} {# Outputs: Privacy Policy #} {# Or empty string if terms with code 'privacy_policy' doesn't exist #} {# Use custom template for link rendering #} {{ setono_sylius_terms_link('terms_and_conditions', '@App/custom_link.html.twig') }} {# Example custom template (@App/custom_link.html.twig): #} {% if terms %} {{ terms.name }} {% endif %} ``` -------------------------------- ### Override Sylius Checkout Complete Form with Terms Field Source: https://github.com/setono/syliustermsplugin/blob/2.x/README.md This Twig code demonstrates how to override the Sylius checkout complete form to include the terms and conditions field. It checks if the 'terms' form field is defined before rendering it, ensuring compatibility with existing templates. ```twig {# templates/bundles/SyliusShopBundle/Checkout/Complete/_form.html.twig #} {% if form.terms is defined %} {{ form_row(form.terms) }} {% endif %} ``` ```twig {# templates/bundles/SyliusShopBundle/Checkout/Complete/_form.html.twig #} {{ form_row(form.notes, {'attr': {'rows': 3}}) }} {% if form.terms is defined %} {{ form_row(form.terms) }} {% endif %} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.