Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Cms Laravel Package

craftcms/cms

Craft CMS is a flexible, user-friendly PHP CMS for building custom web experiences. Features a Twig templating system, auto-generated GraphQL API for headless builds, ecommerce via Craft Commerce, a plugin store, and a powerful extension framework.

View on GitHub
Deep Wiki
Context7
## Getting Started

### **First Steps**
1. **Installation**
   - Require the latest stable version via Composer (ensure compatibility with Laravel/Craft integration):
     ```bash
     composer require craftcms/cms:^5.10.3
     ```
   - Publish the package assets (if needed):
     ```bash
     php craft install
     ```
   - Run migrations (note: no new columns in this release, but verify existing migrations):
     ```bash
     php craft migrate/up
     ```

2. **Initial Setup**
   - **Runtime Path Configuration**: Override the runtime path in `config/app.php` (now officially supported):
     ```php
     return [
         'runtimePath' => storage_path('craft/runtime'), // Custom runtime path
     ];
     ```
   - Define your first **Field Type**, **Plugin**, or **Module** as before (unchanged workflow).

3. **First Use Case: Optimizing Queries**
   - Leverage the new query optimizations for eager-loaded entries or image transforms:
     ```php
     // Example: Reduced queries for nested entries
     $entries = craft()->entries->getEntryById($id)
         ->with(['relatedEntries', 'author'])
         ->one();
     ```

---

## Implementation Patterns

### **Core Workflows**
1. **Content Modeling**
   - **Single Section Entries**: Fixed bug where post dates weren't saved initially. Ensure `postDate` is set explicitly:
     ```php
     $entry->postDate = new \DateTime(); // Explicitly set post date
     craft()->entries->saveEntry($entry);
     ```
   - **Matrix Fields**: Fixed initialization issues for pasted nested entries in Blocks view:
     ```php
     // Safe to paste nested entries in Matrix fields
     $matrixBlock->setContentFromPost($postData);
     ```

2. **Plugin Development**
   - **Runtime Path**: Use `Craft::$app->getRuntimePath()` instead of deprecated `craft\services\Path::getRuntimePath()`:
     ```php
     $runtimePath = Craft::$app->getRuntimePath();
     ```
   - **Security**: Audit plugins for the fixed authorization bypass vulnerabilities (see [security policy](https://github.com/craftcms/cms/security/policy)).

3. **Templates & Twig**
   - **Image Transforms**: Optimized queries for transforms. Cache transforms aggressively:
     ```twig
     {% set transform = craft.app.imageTransformer.transform('myTransform', entry.image) %}
     {{ transform.getUrl() }}
     ```
   - **Matrix Blocks**: Fixed preview values for collapsed blocks with custom UI labels:
     ```twig
     {% for block in entry.myMatrixField %}
         {{ block.title|default('Custom Label') }} {# Fallback for collapsed blocks #}
     {% endfor %}
     ```

4. **API & Webhooks**
   - **Revisions**: Fixed bug where nested elements could be deleted during revision reverts. Test thoroughly:
     ```php
     // Safe to revert revisions with nested elements
     $entry->revertToRevision($revisionId);
     ```

---

### **Integration Tips**
- **Laravel Integration**: Use `Craft::$app->getRuntimePath()` for consistent runtime path handling:
  ```php
  public function boot()
  {
      $this->app->bind('craftRuntimePath', function () {
          return Craft::$app->getRuntimePath();
      });
  }
  • Asset Optimization: Leverage query optimizations for image transforms in asset bundles:
    craft()->assets->registerAssetBundle('MyPlugin', \myplugin\web\assets\MyAsset::class, [
        'transforms' => ['myTransform'], // Predefined transforms
    ]);
    
  • Matrix Field Handling: Use setContentFromPost() for pasted content in Blocks view (fixed initialization bug):
    $matrixBlock->setContentFromPost($request->post('blocks'));
    
  • Security Audits: Scan plugins for:
    • Hardcoded paths (use Craft::$app->getRuntimePath()).
    • Authorization logic (fixed vulnerabilities in this release).

Gotchas and Tips

Common Pitfalls

  1. Runtime Path Deprecation

    • Avoid: craft\services\Path::getRuntimePath() (deprecated).
    • Use: Craft::$app->getRuntimePath().
    • Fix: Update all plugin/service code using the old path service.
  2. Single Section Post Dates

    • Bug: Post dates weren't saved initially for Single section entries.
    • Fix: Explicitly set postDate before saving:
      $entry->postDate = new \DateTime(); // Required for Single sections
      
  3. Matrix Field Initialization

    • Bug: Pasted nested entries in Matrix fields (Blocks view) weren't fully initialized.
    • Fix: Use setContentFromPost() for pasted content (now reliable).
  4. Collapsed Matrix Blocks

    • Bug: Preview values showed "Entry [ID]" for blocks without UI labels.
    • Fix: Provide custom labels or use fallbacks in templates:
      {{ block.title|default('Untitled Block') }}
      
  5. Revision Reverts

    • Bug: Nested elements could be deleted during revision reverts.
    • Fix: Test thoroughly if your plugin uses revertToRevision().
  6. Query Optimization

    • Note: Reduced queries for eager-loaded entries/transforms. Monitor performance gains in:
      • Nested entry queries.
      • Image transform generation.
  7. Security Vulnerabilities

    • Fixed: Two authorization bypass vulnerabilities (moderate/low severity).
    • Action: Audit plugins for:
      • Improper access checks.
      • Hardcoded permissions.
      • Sensitive data exposure.

Debugging Tips

  • Query Logging: Enable to verify optimizations:
    // config/general.php
    'enableQueryLogging' => true,
    
  • Matrix Debugging: Check for initialization issues with pasted content in Blocks view:
    php craft debug/matrix --verbose
    
  • Runtime Path Issues: Verify custom runtime paths:
    php craft info | grep "Runtime Path"
    
  • Authorization Errors: Test edge cases after security fixes:
    php craft security/check --level=high
    

Extension Points

  1. Runtime Path Customization

    • Override in config/app.php:
      return [
          'runtimePath' => storage_path('custom/runtime'),
      ];
      
  2. Matrix Field Events

    • Listen for MATRIX_BLOCK_INITIALIZE to handle pasted content:
      Event::on(
          MatrixBlockType::class,
          MatrixBlockType::EVENT_INITIALIZE_FROM_POST,
          function (Event $event) {
              // Custom initialization logic
          }
      );
      
  3. Image Transform Hooks

    • Extend transform generation with IMAGE_TRANSFORM_BUILD:
      Event::on(
          ImageTransform::class,
          ImageTransform::EVENT_BUILD,
          function (Event $event) {
              // Optimize transform generation
          }
      );
      
  4. Revision Safety

    • Implement custom logic for ELEMENT_REVERT to handle nested elements:
      Event::on(
          Element::class,
          Element::EVENT_REVERT,
          function (Event $event) {
              // Preserve nested elements during revert
          }
      );
      

Pro Tips

  • Leverage Query Optimizations: Test performance gains in:
    • Complex entry queries with .with().
    • Image transform-heavy templates.
  • Security Best Practices:
    • Use Craft::$app->getUser()->can() for authorization.
    • Avoid hardcoded paths (use Craft::$app->getRuntimePath()).
  • Matrix Field Workflows:
    • Prefer setContentFromPost() for pasted content.
    • Provide UI labels for collapsed blocks to avoid "Entry [ID]" previews.
  • Runtime Path Management:
    • Centralize runtime path usage in a service:
      class RuntimeService {
          public function getPath(string $subpath = ''): string {
              return Craft::$app->getRuntimePath() . DIRECTORY_SEPARATOR . $subpath;
          }
      }
      

NO_UPDATE_NEEDED was not applicable here due to meaningful updates. The above is the revised assessment.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle